cleanup and adding in socket connection
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
MONGO_CONNECTION_STRING=mongodb+srv://default:M9iZXokJlZpN4KLX@cluster0.mkuqa.mongodb.net/default?retryWrites=true&w=majority
|
||||
|
||||
JWT_TOKEN_SECRET=afajdslfwk1@lkkasdfl21ASDF!2
|
||||
@@ -4,6 +4,7 @@ import * as Tracing from '@sentry/tracing';
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
import express, { Application, NextFunction, Request, Response } from 'express';
|
||||
|
||||
import InitializeWs from './src/socket';
|
||||
import cors from 'cors';
|
||||
import morgan from 'morgan';
|
||||
|
||||
@@ -31,9 +32,11 @@ const server = app.listen(PORT, () =>
|
||||
// won't catch any errors here and we don't want it to
|
||||
console.log();
|
||||
|
||||
require('socket.io')(server, {
|
||||
const io = require('socket.io')(server, {
|
||||
// todo: add authentication
|
||||
cors: {
|
||||
origin: '*',
|
||||
},
|
||||
});
|
||||
|
||||
InitializeWs(io);
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
export default function InitializeWs(io: any) {
|
||||
console.log('initializing web sockets');
|
||||
|
||||
return io
|
||||
.use(function (socket: any, next: any) {
|
||||
console.log('authenticating user...');
|
||||
|
||||
try {
|
||||
// const { token } = socket.handshake.query;
|
||||
// console.log(token);
|
||||
|
||||
// verify jwt token with our api secret
|
||||
// var decoded: JwtClaims = jwt.verify(token, config.JWT_TOKEN_SECRET);
|
||||
|
||||
// socket.userInfo = decoded;
|
||||
|
||||
next();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
next(new Error('WS Authentication Error'));
|
||||
}
|
||||
})
|
||||
.on('connection', (socket: any) => {
|
||||
console.log(`connected`, socket.id);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user