Version 0.2.2 Add multiple cookie token #2

This commit is contained in:
Raphix
2023-08-22 18:19:52 +02:00
parent 95d868b411
commit f567c23ecc
3 changed files with 70 additions and 56 deletions

View File

@ -3,8 +3,7 @@ const { __glob, __web } = require("../modules/global-variables");
const { LogType } = require("./sub-log");
const log = require("./sub-log");
const auth = require("./sub-auth");
const cookieParser = require("cookie-parser");
const { error } = require("console");
const cook = require("cookie")
const wlog = new LogType("Web")
module.exports.WebServer = class {
@ -70,7 +69,32 @@ function init() {
});
server.listen(port);
server.on('error', onError(error, port));
server.on('error', (error) => {
if (error.syscall !== 'listen') {
throw error;
}
let bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// Handle specific listen errors with
// friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind
+ ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
});
server.on('listening', () => {
let addr = server.address();
@ -104,32 +128,6 @@ function normalizePort(val) {
return false;
}
// Event listener for HTTP server "error" event
function onError(error, port) {
if (error.syscall !== 'listen') {
throw error;
}
let bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// Handle specific listen errors with
// friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind
+ ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
function IOConnection(io) {
@ -166,11 +164,12 @@ function IOConnection(io) {
socket.on("GET/USER_INFO", () => {
var token = socket.handshake.headers.cookie
var cookies = socket.handshake.headers.cookie
if(token) {
if(cookies) {
token = socket.handshake.headers.cookie.replace("token=", "")
cookies = cook.parse(cookies)
var token = cookies.token
if(auth.checkUser(token)) {