Docker + Updated Redis

This commit is contained in:
Evann Regnault 2022-11-27 02:13:57 +01:00
parent 8ec4f756f5
commit 325b730942
6 changed files with 27 additions and 14 deletions

3
.dockerignore Normal file
View file

@ -0,0 +1,3 @@
.next/
node_modules/
.idea/

8
.idea/.gitignore vendored
View file

@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

15
Dockerfile Normal file
View file

@ -0,0 +1,15 @@
FROM node:alpine
ENV API_PORT=3000
ENV ENABLE_REDIS=true
ENV REDIS_HOST=localhost
ENV REDIS_PORT=6379
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build
ENTRYPOINT ["npm","run","start"]

View file

@ -3,15 +3,15 @@
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
"start": "next start -p $API_PORT"
},
"dependencies": {
"dayjs": "^1.10.7",
"next": "latest",
"next": "^12.3.4",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"swr": "^1.0.1",
"redis": "^4.0.1",
"redis": "^4.5.1",
"dotenv": "^10.0.0",
"fast-levenshtein": "^3.0.0"
}

View file

@ -5,6 +5,7 @@ export default async function handler(req, res) {
let characters = JSON.parse(await getResultFromRedis('character-all'));
if (!characters){
characters = await getCharacters();
console.log(characters)
addResultToRedis('character-all', JSON.stringify(characters)).catch(console.error)
}
if (characters) {

View file

@ -1,7 +1,9 @@
const ENABLE_REDIS = true;
const ENABLE_REDIS = process.env["ENABLE_REDIS"];
const redis = require("redis");
const client = ENABLE_REDIS ? redis.createClient("redis://localhost:6379") : null;
client?.connect();
const client = redis.createClient({
url: `redis://${process.env['REDIS_HOST']}:${process.env["REDIS_PORT"]}`
});
if (ENABLE_REDIS) (client.connect().then(_ =>{console.info("Connected to redis")}));
export async function getResultFromRedis(key){