2023-09-02 12:13:50 +00:00
|
|
|
import 'dotenv/config';
|
2023-09-14 16:53:03 +00:00
|
|
|
import './init';
|
2023-08-31 13:17:57 +00:00
|
|
|
import express from 'express';
|
2023-09-02 17:01:55 +00:00
|
|
|
import 'express-async-errors';
|
2023-08-31 13:17:57 +00:00
|
|
|
import ViteExpress from 'vite-express';
|
2023-09-02 14:53:57 +00:00
|
|
|
import compression from 'compression';
|
2023-09-02 17:01:55 +00:00
|
|
|
import passport from 'passport';
|
2023-09-05 06:08:38 +00:00
|
|
|
import morgan from 'morgan';
|
2023-09-03 11:28:53 +00:00
|
|
|
import { userRouter } from './router/user';
|
|
|
|
import { websiteRouter } from './router/website';
|
2023-09-04 17:18:43 +00:00
|
|
|
import { workspaceRouter } from './router/workspace';
|
2023-09-17 06:41:40 +00:00
|
|
|
import { telemetryRouter } from './router/telemetry';
|
2023-09-27 09:56:32 +00:00
|
|
|
import { trpcExpressMiddleware } from './trpc';
|
2023-09-30 16:01:43 +00:00
|
|
|
import { initUdpServer } from './udp/server';
|
2023-10-03 11:47:17 +00:00
|
|
|
import { createServer } from 'http';
|
|
|
|
import { initSocketio } from './ws';
|
2023-09-02 17:01:55 +00:00
|
|
|
|
2023-09-04 17:18:43 +00:00
|
|
|
const port = Number(process.env.PORT || 12345);
|
2023-08-31 13:17:57 +00:00
|
|
|
|
|
|
|
const app = express();
|
2023-10-03 11:47:17 +00:00
|
|
|
const httpServer = createServer(app);
|
2023-08-31 13:17:57 +00:00
|
|
|
|
2023-09-30 16:01:43 +00:00
|
|
|
initUdpServer(port);
|
|
|
|
|
2023-10-03 11:47:17 +00:00
|
|
|
initSocketio(httpServer);
|
2023-09-18 08:08:16 +00:00
|
|
|
|
2023-09-02 14:53:57 +00:00
|
|
|
app.use(compression());
|
|
|
|
app.use(express.json());
|
2023-09-02 17:01:55 +00:00
|
|
|
app.use(passport.initialize());
|
2023-10-03 11:47:17 +00:00
|
|
|
// app.use(morgan('tiny'));
|
2023-09-02 14:53:57 +00:00
|
|
|
|
|
|
|
// http://expressjs.com/en/advanced/best-practice-security.html#at-a-minimum-disable-x-powered-by-header
|
|
|
|
app.disable('x-powered-by');
|
|
|
|
|
|
|
|
app.use('/api/user', userRouter);
|
2023-09-03 11:28:53 +00:00
|
|
|
app.use('/api/website', websiteRouter);
|
2023-09-04 17:18:43 +00:00
|
|
|
app.use('/api/workspace', workspaceRouter);
|
2023-09-17 06:41:40 +00:00
|
|
|
app.use('/api/telemetry', telemetryRouter);
|
2023-09-02 14:53:57 +00:00
|
|
|
|
2023-09-27 09:56:32 +00:00
|
|
|
app.use('/trpc', trpcExpressMiddleware);
|
|
|
|
|
2023-09-02 14:53:57 +00:00
|
|
|
app.use((err: any, req: any, res: any, next: any) => {
|
2023-09-03 13:05:22 +00:00
|
|
|
console.error(err);
|
|
|
|
res.status(500).json({ message: err.message });
|
2023-08-31 13:17:57 +00:00
|
|
|
});
|
|
|
|
|
2023-10-03 11:47:17 +00:00
|
|
|
httpServer.listen(port, () => {
|
|
|
|
ViteExpress.bind(app, httpServer, () => {
|
|
|
|
console.log(`Server is listening on port ${port}...`);
|
|
|
|
console.log(`Website: http://127.0.0.1:${port}`);
|
|
|
|
});
|
2023-08-31 13:17:57 +00:00
|
|
|
});
|