Spaces:
Sleeping
Sleeping
ambatukammm
Browse files
server.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
| 1 |
const express = require('express');
|
| 2 |
const app = express();
|
| 3 |
const http = require('http').createServer(app);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
const io = require('socket.io')(http, {
|
| 5 |
cors: {
|
| 6 |
origin: "*",
|
| 7 |
methods: ["GET", "POST"]
|
| 8 |
}
|
| 9 |
});
|
| 10 |
-
const crypto = require('crypto');
|
| 11 |
|
| 12 |
app.use(express.json());
|
| 13 |
app.use((req, res, next) => {
|
|
@@ -17,15 +24,6 @@ app.use((req, res, next) => {
|
|
| 17 |
next();
|
| 18 |
});
|
| 19 |
|
| 20 |
-
const SECRET_PASSWORD = process.env.SECRET_PASSWORD
|
| 21 |
-
const SECRET_KEY = crypto.createHash('md5').update(SECRET_PASSWORD).digest('hex');
|
| 22 |
-
|
| 23 |
-
const validTokens = new Map();
|
| 24 |
-
const users = {};
|
| 25 |
-
const chatHistory = [];
|
| 26 |
-
const MAX_CHAT_HISTORY = 500;
|
| 27 |
-
const TOKEN_EXPIRY_MS = 7 * 24 * 60 * 60 * 1000;
|
| 28 |
-
|
| 29 |
function generateSignedToken(username) {
|
| 30 |
const randomToken = crypto.randomBytes(16).toString('hex');
|
| 31 |
const timestamp = Date.now().toString();
|
|
@@ -71,9 +69,8 @@ app.get('/', (req, res) => {
|
|
| 71 |
activeTokens: validTokens.size,
|
| 72 |
onlineUsers: Object.keys(users).length,
|
| 73 |
chatHistory: chatHistory.length
|
| 74 |
-
}
|
| 75 |
});
|
| 76 |
-
);
|
| 77 |
|
| 78 |
app.get('/health', (req, res) => {
|
| 79 |
res.json({ status: 'healthy' });
|
|
|
|
| 1 |
const express = require('express');
|
| 2 |
const app = express();
|
| 3 |
const http = require('http').createServer(app);
|
| 4 |
+
const crypto = require('crypto');
|
| 5 |
+
const SECRET_PASSWORD = process.env.SECRET_PASSWORD
|
| 6 |
+
const SECRET_KEY = crypto.createHash('md5').update(SECRET_PASSWORD).digest('hex');
|
| 7 |
+
const validTokens = new Map();
|
| 8 |
+
const users = {};
|
| 9 |
+
const chatHistory = [];
|
| 10 |
+
const MAX_CHAT_HISTORY = 500;
|
| 11 |
+
const TOKEN_EXPIRY_MS = 7 * 24 * 60 * 60 * 1000;
|
| 12 |
const io = require('socket.io')(http, {
|
| 13 |
cors: {
|
| 14 |
origin: "*",
|
| 15 |
methods: ["GET", "POST"]
|
| 16 |
}
|
| 17 |
});
|
|
|
|
| 18 |
|
| 19 |
app.use(express.json());
|
| 20 |
app.use((req, res, next) => {
|
|
|
|
| 24 |
next();
|
| 25 |
});
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
function generateSignedToken(username) {
|
| 28 |
const randomToken = crypto.randomBytes(16).toString('hex');
|
| 29 |
const timestamp = Date.now().toString();
|
|
|
|
| 69 |
activeTokens: validTokens.size,
|
| 70 |
onlineUsers: Object.keys(users).length,
|
| 71 |
chatHistory: chatHistory.length
|
|
|
|
| 72 |
});
|
| 73 |
+
});
|
| 74 |
|
| 75 |
app.get('/health', (req, res) => {
|
| 76 |
res.json({ status: 'healthy' });
|