diff options
author | Mark Powers <mark@marks.kitchen> | 2024-07-14 15:32:55 -0500 |
---|---|---|
committer | Mark Powers <mark@marks.kitchen> | 2024-07-14 15:33:12 -0500 |
commit | 4c61d4a45c5c0e3639659312e57a9a38bc266b4a (patch) | |
tree | 7c0895d810d3eb0ef91812780b42bcc94bd5039a | |
parent | 80f0830f757b16d2c03ac8f427a6fa9608ef9bf9 (diff) |
-rw-r--r-- | Dockerfile | 9 | ||||
-rw-r--r-- | docker-compose.yml | 41 | ||||
-rw-r--r-- | src/index.js | 14 | ||||
-rw-r--r-- | src/server.js | 2 |
4 files changed, 58 insertions, 8 deletions
diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5ff1678 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM node:20-slim + +COPY package.json . +COPY package-lock.json . +COPY src/ ./src + +RUN npm install + +CMD node src/ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..cacc13c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,41 @@ +version: "3.8" + +services: + kitchen: + build: + context: . + ports: + - "8080:8080" + depends_on: + kitchen_db: + condition: service_healthy + environment: + - DATABASE=kitchen + - DATABASE_USER=kitchen + - DATABASE_PASS=kitchen + - DATABASE_HOST=kitchen_db + - JWT_SECRET=something_secret + kitchen_db: + image: mysql + command: --default-authentication-plugin=mysql_native_password + environment: + - MYSQL_USER=kitchen + - MYSQL_PASSWORD=kitchen + - MYSQL_ROOT_PASSWORD=kitchen + - MYSQL_DATABASE=kitchen + volumes: + - kitchen-db:/var/lib/mysql + healthcheck: + test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"] + timeout: 20s + retries: 10 + games: + image: games + ports: + - "8081:8080" + environment: + - DATABASE=kitchen + - JWT_SECRET=something_secret + +volumes: + kitchen-db: diff --git a/src/index.js b/src/index.js index a7dff9b..31ae590 100644 --- a/src/index.js +++ b/src/index.js @@ -4,10 +4,8 @@ const fs = require('fs'); const path = require('path'); const jwt = require('jsonwebtoken'); -const config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json'))); - -const dbCreds = config.database; -const secret = config.jwt_secret; +const { env } = require('node:process'); +const secret = env.JWT_SECRET const jwtFunctions = { sign: function(message) { @@ -18,7 +16,7 @@ const jwtFunctions = { } } -const database = new Sequelize(dbCreds.database, dbCreds.user, dbCreds.password, { +const database = new Sequelize(env.DATABASE, env.DATABASE_USER, env.DATABASE_PASS, { logging(str) { console.debug(`DB:${str}`); }, @@ -26,7 +24,7 @@ const database = new Sequelize(dbCreds.database, dbCreds.user, dbCreds.password, charset: 'utf8mb4', multipleStatements: true, }, -// host: dbCreds.host, + host: env.DATABASE_HOST, dialect: 'mysql', pool: { max: 5, @@ -36,7 +34,7 @@ const database = new Sequelize(dbCreds.database, dbCreds.user, dbCreds.password, }); database.authenticate().then(() => { - console.debug(`database connection successful: ${dbCreds.database}`); + console.debug(`database connection successful: ${env.DATABASE}`); }, (e) => console.log(e)); async function sync(alter, force, callback) { @@ -114,5 +112,5 @@ const models = setUpModels(); const templates = require('./templates'); sync(); server.setUpRoutes(models, jwtFunctions, database, templates.setUpTemplates()); -server.listen(config.port); +server.listen(8080); diff --git a/src/server.js b/src/server.js index b2b8d25..ff93d8f 100644 --- a/src/server.js +++ b/src/server.js @@ -153,6 +153,7 @@ function setUpRoutes(models, jwtFunctions, database, templates) { next(); }) + /* // Route logging server.use(function (req, res, next) { let cookie = req.cookies.session; @@ -165,6 +166,7 @@ function setUpRoutes(models, jwtFunctions, database, templates) { }); next() }) + */ server.get('/', cache('5 minutes'), async (req, res) => { let posts = await formatPostsForType(models, "index") |