mirror of
https://codeberg.org/SafeTwitch/safetwitch-backend.git
synced 2024-12-23 05:32:59 -05:00
34 lines
700 B
TypeScript
34 lines
700 B
TypeScript
|
import express, { Express } from 'express';
|
||
|
import dotenv from 'dotenv'
|
||
|
import routes from './routes'
|
||
|
import { errorHandler, uuid } from './util/logger'
|
||
|
import { wsServer } from './routes/proxyRoute';
|
||
|
|
||
|
dotenv.config()
|
||
|
|
||
|
const app: Express = express();
|
||
|
const port = process.env.PORT
|
||
|
|
||
|
app.use(uuid)
|
||
|
app.use(routes)
|
||
|
|
||
|
// 404 handler
|
||
|
app.use((req, res) => {
|
||
|
if (!res.headersSent) {
|
||
|
res.status(404).send('404')
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// handle errors
|
||
|
app.use(errorHandler)
|
||
|
|
||
|
const server = app.listen(port, () => {
|
||
|
console.log('Server up')
|
||
|
})
|
||
|
|
||
|
server.on('upgrade', (request, socket, head) => {
|
||
|
wsServer.handleUpgrade(request, socket, head, socket => {
|
||
|
wsServer.emit('connection', socket, request);
|
||
|
});
|
||
|
});
|