0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2025-01-09 06:10:09 -05:00
safetwitch-backend/index.ts

39 lines
926 B
TypeScript
Raw Normal View History

2023-03-24 06:41:33 -05:00
import express, { Express } from 'express';
import dotenv from 'dotenv'
import routes from './routes'
import { errorHandler } from './util/errorHandler'
2023-03-24 06:41:33 -05:00
import { wsServer } from './routes/proxyRoute';
2023-03-29 09:03:16 -05:00
import compression from 'compression'
import { version } from './package.json';
2023-03-24 06:41:33 -05:00
dotenv.config()
const app: Express = express();
const port = process.env.PORT
2023-03-29 09:03:16 -05:00
app.use(compression({}))
2023-03-24 06:41:33 -05:00
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(`SafeTwitch v${version} started on port ${port}`)
2023-03-24 06:41:33 -05:00
})
server.on('upgrade', (request, socket, head) => {
wsServer.handleUpgrade(request, socket, head, socket => {
wsServer.emit('connection', socket, request);
});
});
2023-03-29 09:03:16 -05:00
// don't crash on unhandledRejection
process.on('unhandledRejection', (reason: Error, p) => {});