Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b5cbaea17 | |||
| 0f2b8d3f52 | |||
| 88c2239fdb | |||
| b5f9d0a7fc | |||
| 1ec29e4519 | |||
| a15c43b3d0 | |||
| 9bc96bdb5f | |||
| 4bdcee11ea | |||
| e1cd1ec001 | |||
| e8a9a79687 | |||
| 7d628be826 | |||
| 7a42ab3108 | |||
| ec573e1074 | |||
| 9c5033daea | |||
| fb4d857224 | |||
| e0d6260d1a | |||
| 53ea726c89 | |||
| c44ed79e6d | |||
| 518f5dbee7 | |||
| be57dbe51c | |||
| 8309c3b832 | |||
| 95d229c561 | |||
| 0b1456ebde | |||
| bd5b6e8233 | |||
| 05eecf8bdd | |||
| 2aedb6e938 | |||
| ab73d05471 | |||
| f72b0e5522 | |||
| 900312752b | |||
| 1b2868d68f |
@@ -1,5 +1,7 @@
|
||||
WEB_PORT=3300
|
||||
|
||||
WEB_ORIGIN=http://localhost:3001
|
||||
|
||||
DB_HOSTNAME=database
|
||||
DB_DATABASE=chat
|
||||
DB_USERNAME=chat
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
patreon: krgamestudios
|
||||
ko_fi: krgamestudios
|
||||
custom: ["https://www.paypal.com/donate/?hosted_button_id=73Q82T2ZHV8AA"]
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
|
||||
FROM node:16
|
||||
FROM node:18-bullseye-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.
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
An API centric chat server. Uses Sequelize and mariaDB by default.
|
||||
|
||||
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.
|
||||
@@ -13,7 +15,7 @@ POST https://dev-auth.krgamestudios.com/auth/login HTTP/1.1
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"email": "kayneruse@gmail.com",
|
||||
"email": "example@example.com",
|
||||
"password": "helloworld"
|
||||
}
|
||||
```
|
||||
|
||||
+4
-2
@@ -30,10 +30,11 @@ const question = (prompt, def = null) => {
|
||||
//project configuration
|
||||
const appName = await question('App Name', 'chat');
|
||||
const appWebAddress = await question('Web Addr', `${appName}.example.com`);
|
||||
const appWebOrigin = await question('Web Origin', `https://example.com`); //TODO: clean these up properly
|
||||
const appPort = await question('App Port', '3300');
|
||||
|
||||
const appDBUser = await question('DB User', appName);
|
||||
const appDBPass = await question('DB Pass', uuid());
|
||||
const appDBPass = await question('DB Pass', 'blastoise');
|
||||
const dbRootPass = await question('DB Root Pass');
|
||||
|
||||
const appSecretAccess = await question('Access Token Secret', uuid(32));
|
||||
@@ -59,6 +60,7 @@ services:
|
||||
- "traefik.http.services.${appName}service.loadbalancer.server.port=${appPort}"
|
||||
environment:
|
||||
- WEB_PORT=${appPort}
|
||||
- WEB_ORIGIN=${appWebOrigin}
|
||||
- DB_HOSTNAME=database
|
||||
- DB_DATABASE=${appName}
|
||||
- DB_USERNAME=${appDBUser}
|
||||
@@ -108,7 +110,7 @@ networks:
|
||||
`;
|
||||
|
||||
const dockerfile = `
|
||||
FROM node:16
|
||||
FROM node:18-bullseye-slim
|
||||
WORKDIR "/app"
|
||||
COPY package*.json ./
|
||||
RUN npm install --production
|
||||
|
||||
Generated
+478
-2982
File diff suppressed because it is too large
Load Diff
+11
-8
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "chat-server",
|
||||
"version": "1.2.4",
|
||||
"version": "1.4.6",
|
||||
"description": "An API centric chat server. Uses Sequelize and mariaDB by default.",
|
||||
"main": "server/server.js",
|
||||
"scripts": {
|
||||
@@ -20,14 +20,17 @@
|
||||
"homepage": "https://github.com/krgamestudios/chat-server#readme",
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^8.6.0",
|
||||
"express": "^4.17.1",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"mariadb": "^2.5.4",
|
||||
"sequelize": "^6.6.5",
|
||||
"socket.io": "^4.1.3"
|
||||
"dotenv": "^16.3.1",
|
||||
"express": "^4.18.2",
|
||||
"jsonwebtoken": "^9.0.0",
|
||||
"mariadb": "^3.2.0",
|
||||
"sequelize": "^6.32.1",
|
||||
"socket.io": "^4.7.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.12"
|
||||
"nodemon": "^2.0.22"
|
||||
},
|
||||
"overrides": {
|
||||
"semver": "^7.5.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ const chat = io => {
|
||||
});
|
||||
|
||||
//from here, handles all normal messages
|
||||
socket.on('open chat', message => {
|
||||
socket.on('open chat', async message => {
|
||||
//handle rooms - only in a room if you've opened chat
|
||||
const newlyOpened = !socket.user.room;
|
||||
socket.user.room = socket.user.room || 'general'; //default to general
|
||||
@@ -46,11 +46,8 @@ const chat = io => {
|
||||
|
||||
socket.join(socket.user.room);
|
||||
|
||||
//broadcast to this room
|
||||
socket.broadcast.to(socket.user.room).emit('message', { emphasis: true, text: `${socket.user.username} entered chat` });
|
||||
|
||||
//log
|
||||
chatlog.create({
|
||||
const log = await chatlog.create({
|
||||
notification: true,
|
||||
username: socket.user.username,
|
||||
text: `${socket.user.username} entered chat`,
|
||||
@@ -58,6 +55,9 @@ const chat = io => {
|
||||
emphasis: true
|
||||
});
|
||||
|
||||
//broadcast to this room
|
||||
socket.broadcast.to(socket.user.room).emit('message', {timestamp: log.createdAt, emphasis: true, text: `${socket.user.username} entered chat` });
|
||||
|
||||
//send backlog to the user
|
||||
chatlog.findAll({
|
||||
where: {
|
||||
@@ -120,7 +120,7 @@ const chat = io => {
|
||||
socket.broadcast.to(socket.user.room).emit('message', log);
|
||||
});
|
||||
|
||||
socket.on('disconnect', reason => {
|
||||
socket.on('disconnect', async reason => {
|
||||
//broadcast to this room
|
||||
if (!socket.user) {
|
||||
return;
|
||||
|
||||
+7
-2
@@ -7,14 +7,19 @@ const app = express();
|
||||
const server = require('http').Server(app);
|
||||
const io = require('socket.io')(server, {
|
||||
cors: {
|
||||
origin: '*'
|
||||
origin: process.env.WEB_ORIGIN
|
||||
}
|
||||
});
|
||||
const cors = require('cors');
|
||||
|
||||
//config
|
||||
app.use(express.json());
|
||||
app.use(cors());
|
||||
app.use(cors({
|
||||
credentials: true,
|
||||
origin: [`${process.env.WEB_ORIGIN}`], //because auth-server
|
||||
allowedHeaders: ['Origin', 'X-Requested-With', 'Content-Type', 'Accept', 'Authorization', 'Set-Cookie'],
|
||||
exposedHeaders: ['Origin', 'X-Requested-With', 'Content-Type', 'Accept', 'Authorization', 'Set-Cookie'],
|
||||
}));
|
||||
|
||||
//database connection
|
||||
const database = require('./database');
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
#use this while debugging
|
||||
CREATE DATABASE IF NOT EXISTS chat;
|
||||
CREATE USER IF NOT EXISTS 'chat'@'%' IDENTIFIED BY 'blastoise';
|
||||
GRANT ALL PRIVILEGES ON chat.* TO 'chat'@'%';
|
||||
Reference in New Issue
Block a user