Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 496048f62b | |||
| 2e8c3f98ca | |||
| 582c0b453c | |||
| 9db6dbf63b | |||
| 3700372e92 | |||
| 416ab2f3f9 | |||
| 1b5cbaea17 | |||
| 0f2b8d3f52 | |||
| 88c2239fdb | |||
| b5f9d0a7fc | |||
| 1ec29e4519 | |||
| a15c43b3d0 | |||
| 9bc96bdb5f | |||
| 4bdcee11ea | |||
| e1cd1ec001 | |||
| e8a9a79687 | |||
| 7d628be826 | |||
| 7a42ab3108 | |||
| ec573e1074 |
@@ -2,7 +2,9 @@ WEB_PORT=3300
|
||||
|
||||
WEB_ORIGIN=http://localhost:3001
|
||||
|
||||
DB_HOSTNAME=database
|
||||
DB_HOSTNAME=localhost
|
||||
DB_PORTNAME=3306
|
||||
|
||||
DB_DATABASE=chat
|
||||
DB_USERNAME=chat
|
||||
DB_PASSWORD=blastoise
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
FROM node:18
|
||||
|
||||
FROM node:22-bookworm-slim
|
||||
WORKDIR "/app"
|
||||
COPY package*.json ./
|
||||
COPY package*.json /app
|
||||
RUN npm install --production
|
||||
COPY . /app
|
||||
EXPOSE 3300
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2021 Kayne Ruse, KR Game Studios
|
||||
Copyright (c) 2021-2023 Kayne Ruse, KR Game Studios
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ This server is available via docker hub at krgamestudios/chat-server.
|
||||
|
||||
# Setup
|
||||
|
||||
There are multiple ways to run this app - it can run on it's own via `npm start` (for production) or `npm run dev` (for development). it can also run inside docker using `docker-compose up --build` - run `node configure-script.js` to generate docker-compose.yml and startup.sql.
|
||||
There are multiple ways to run this app - it can run on it's own via `npm start` (for production) or `npm run dev` (for development). it can also run inside docker using `docker compose up --build` - run `node configure-script.js` to generate docker-compose.yml and startup.sql.
|
||||
|
||||
To generate an authorization token, use [auth-server](https://github.com/krgamestudios/auth-server). A public-facing development auth-server is available here (tokens are valid for 10 minutes):
|
||||
|
||||
|
||||
+55
-26
@@ -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');
|
||||
@@ -43,38 +62,42 @@ const question = (prompt, def = null) => {
|
||||
|
||||
//generate the files
|
||||
const ymlfile = `
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
${appName}:
|
||||
build:
|
||||
context: .
|
||||
ports:
|
||||
- "${appPort}"
|
||||
- ${appPort}
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.${appName}router.rule=Host(\`${appWebAddress}\`)"
|
||||
- "traefik.http.routers.${appName}router.entrypoints=websecure"
|
||||
- "traefik.http.routers.${appName}router.tls.certresolver=myresolver"
|
||||
- "traefik.http.routers.${appName}router.service=${appName}service@docker"
|
||||
- "traefik.http.services.${appName}service.loadbalancer.server.port=${appPort}"
|
||||
- traefik.enable=true
|
||||
- traefik.http.routers.${appName}router.rule=Host(\`${appWebAddress}\`)
|
||||
- traefik.http.routers.${appName}router.entrypoints=websecure
|
||||
- traefik.http.routers.${appName}router.tls.certresolver=myresolver
|
||||
- traefik.http.routers.${appName}router.service=${appName}service@docker
|
||||
- traefik.http.services.${appName}service.loadbalancer.server.port=${appPort}
|
||||
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}
|
||||
volumes:
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
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}
|
||||
@@ -83,34 +106,40 @@ services:
|
||||
volumes:
|
||||
- ./mysql:/var/lib/mysql
|
||||
- ./startup.sql:/docker-entrypoint-initdb.d/startup.sql:ro
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
- /etc/localtime:/etc/localtime:ro`}
|
||||
|
||||
traefik_${appName}:
|
||||
container_name: ${appName}_traefik
|
||||
image: "traefik:v2.4"
|
||||
container_name: "traefik"
|
||||
image: traefik:v2.10
|
||||
container_name: traefik
|
||||
command:
|
||||
- "--log.level=ERROR"
|
||||
- "--api.insecure=false"
|
||||
- "--providers.docker=true"
|
||||
- "--providers.docker.exposedbydefault=false"
|
||||
- "--entrypoints.websecure.address=:443"
|
||||
- "--certificatesresolvers.myresolver.acme.tlschallenge=true"
|
||||
- "--certificatesresolvers.myresolver.acme.email=${supportEmail}"
|
||||
- "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
|
||||
- --log.level=ERROR
|
||||
- --api.insecure=false
|
||||
- --providers.docker=true
|
||||
- --providers.docker.exposedbydefault=false
|
||||
- --entrypoints.websecure.address=:443
|
||||
- --certificatesresolvers.myresolver.acme.tlschallenge=true
|
||||
- --certificatesresolvers.myresolver.acme.email=${supportEmail}
|
||||
- --certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
- 80:80
|
||||
- 443:443
|
||||
volumes:
|
||||
- "./letsencrypt:/letsencrypt"
|
||||
- "/var/run/docker.sock:/var/run/docker.sock:ro"
|
||||
- ./letsencrypt:/letsencrypt
|
||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
networks:
|
||||
- app-network
|
||||
|
||||
networks:
|
||||
app-network:
|
||||
driver: bridge
|
||||
`;
|
||||
|
||||
const dockerfile = `
|
||||
FROM node:18
|
||||
FROM node:22-bookworm-slim
|
||||
WORKDIR "/app"
|
||||
COPY package*.json ./
|
||||
RUN npm install --production
|
||||
|
||||
Generated
+979
-1843
File diff suppressed because it is too large
Load Diff
+9
-9
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "chat-server",
|
||||
"version": "1.3.1",
|
||||
"version": "1.5.1",
|
||||
"description": "An API centric chat server. Uses Sequelize and mariaDB by default.",
|
||||
"main": "server/server.js",
|
||||
"scripts": {
|
||||
@@ -13,21 +13,21 @@
|
||||
"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"
|
||||
},
|
||||
"homepage": "https://github.com/krgamestudios/chat-server#readme",
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.0.1",
|
||||
"express": "^4.17.1",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"mariadb": "^3.0.1",
|
||||
"sequelize": "^6.6.5",
|
||||
"socket.io": "^4.1.3"
|
||||
"dotenv": "^17.2.1",
|
||||
"express": "^5.1.0",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"mariadb": "^3.4.5",
|
||||
"sequelize": "^6.37.7",
|
||||
"socket.io": "^4.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.12"
|
||||
"nodemon": "^3.1.10"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
+2
-1
@@ -31,7 +31,7 @@ app.use('/admin', require('./admin'));
|
||||
require('./chat')(io.of('/chat'));
|
||||
|
||||
//error on access
|
||||
app.get('*', (req, res) => {
|
||||
app.get('/{*any}', (req, res) => {
|
||||
res.redirect('https://github.com/krgamestudios/chat-server');
|
||||
});
|
||||
|
||||
@@ -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 || '<default>'}:${process.env.DB_PORTNAME || '<default>'}`);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#use this while debugging
|
||||
CREATE DATABASE IF NOT EXISTS chat;
|
||||
CREATE USER IF NOT EXISTS 'chat'@'%' IDENTIFIED BY 'blastoise';
|
||||
CREATE DATABASE chat;
|
||||
CREATE USER 'chat'@'%' IDENTIFIED BY 'blastoise';
|
||||
GRANT ALL PRIVILEGES ON chat.* TO 'chat'@'%';
|
||||
|
||||
Reference in New Issue
Block a user