diff --git a/.envdev b/.envdev index 34b3790..9abc3a8 100644 --- a/.envdev +++ b/.envdev @@ -3,6 +3,8 @@ WEB_PORT=3300 WEB_ORIGIN=http://localhost:3001 DB_HOSTNAME=localhost +DB_PORTNAME=3306 + DB_DATABASE=chat DB_USERNAME=chat DB_PASSWORD=blastoise diff --git a/configure-script.js b/configure-script.js index d140d5c..1009c5e 100644 --- a/configure-script.js +++ b/configure-script.js @@ -33,6 +33,25 @@ const question = (prompt, def = null) => { const appWebOrigin = await question('Web Origin', `https://example.com`); //TODO: clean these up properly const appPort = await question('App Port', '3300'); + //configure the database address + let dbLocation = ''; + while (typeof dbLocation != 'string' || /^[le]/i.test(dbLocation[0]) == false) { + dbLocation = await question('[l]ocal or [e]xternal database?'); + } + + let appDBHost = ''; + let appDBPort = ''; + + if (/^[l]/i.test(dbLocation[0])) { + appDBHost = 'database'; + appDBPort = '3306'; + } + else { + appDBHost = await question('DB Host'); + appDBPort = await question('DB Port', '3306'); + } + + //configure the database account const appDBUser = await question('DB User', appName); const appDBPass = await question('DB Pass', 'blastoise'); const dbRootPass = await question('DB Root Pass'); @@ -61,20 +80,22 @@ services: environment: - WEB_PORT=${appPort} - WEB_ORIGIN=${appWebOrigin} - - DB_HOSTNAME=database + - DB_HOSTNAME=${appDBHost} + - DB_PORTNAME=${appDBPort} - DB_DATABASE=${appName} - DB_USERNAME=${appDBUser} - DB_PASSWORD=${appDBPass} - DB_TIMEZONE=Australia/Sydney - SECRET_ACCESS=${appSecretAccess} networks: - - app-network + - app-network${ appDBHost != 'database' ? '' : ` depends_on: - database database: image: mariadb:latest environment: MYSQL_DATABASE: ${appName} + MYSQL_TCP_PORT: ${appDBPort} MYSQL_USER: ${appDBUser} MYSQL_PASSWORD: ${appDBPass} MYSQL_ROOT_PASSWORD: ${dbRootPass} @@ -82,7 +103,7 @@ services: - app-network volumes: - ./mysql:/var/lib/mysql - - ./startup.sql:/docker-entrypoint-initdb.d/startup.sql:ro + - ./startup.sql:/docker-entrypoint-initdb.d/startup.sql:ro`} traefik_${appName}: container_name: ${appName}_traefik image: "traefik:v2.10" diff --git a/package-lock.json b/package-lock.json index cc315ff..34d0da8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,7 @@ "": { "name": "chat-server", "version": "1.5.1", - "license": "ISC", + "license": "Zlib", "dependencies": { "cors": "^2.8.5", "dotenv": "^16.4.5", diff --git a/package.json b/package.json index c5bfd90..b8f9fff 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "url": "git+https://github.com/krgamestudios/chat-server.git" }, "author": "Kayne Ruse", - "license": "ISC", + "license": "Zlib", "bugs": { "url": "https://github.com/krgamestudios/chat-server/issues" }, diff --git a/server/database/index.js b/server/database/index.js index d098b9f..9f9611c 100644 --- a/server/database/index.js +++ b/server/database/index.js @@ -2,11 +2,10 @@ const Sequelize = require('sequelize'); const sequelize = new Sequelize(process.env.DB_DATABASE, process.env.DB_USERNAME, process.env.DB_PASSWORD, { host: process.env.DB_HOSTNAME, + port: process.env.DB_PORTNAME, dialect: 'mariadb', timezone: process.env.DB_TIMEZONE, logging: process.env.DB_LOGGING ? console.log : false }); -sequelize.sync(); - module.exports = sequelize; \ No newline at end of file diff --git a/server/server.js b/server/server.js index 1d14fdc..0edc8fe 100644 --- a/server/server.js +++ b/server/server.js @@ -39,4 +39,5 @@ app.get('*', (req, res) => { server.listen(process.env.WEB_PORT || 3300, async (err) => { await database.sync(); console.log(`listening to localhost:${process.env.WEB_PORT || 3300}`); + console.log(`database located at ${process.env.DB_HOSTNAME || ''}:${process.env.DB_PORTNAME || ''}`); });