30 lines
773 B
JavaScript
30 lines
773 B
JavaScript
import dotenv from "dotenv";
|
|
dotenv.config();
|
|
import express from "express";
|
|
import expressWs from "express-ws";
|
|
import morgan from "morgan";
|
|
import { initWebsocket } from "./websocket.js";
|
|
import { initAuth } from "./auth.js";
|
|
import { close as closeDbConnection, initDbConnection, db } from "./db.js";
|
|
const app = express();
|
|
const appWs = expressWs(app);
|
|
const port = 12345;
|
|
|
|
process.on('exit', function() {
|
|
console.log('Shutting down...');
|
|
console.log('Closing db connection...');
|
|
closeDbConnection();
|
|
});
|
|
|
|
app.use(morgan(process.env.production ? 'common' : 'dev'));
|
|
app.use(express.json());
|
|
|
|
await initDbConnection();
|
|
|
|
initAuth(app, db);
|
|
initWebsocket(app);
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Listening on port ${port}`);
|
|
});
|