-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
41 lines (36 loc) · 1.03 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import express from 'express';
import cors from 'cors';
import {useUserRoute} from './service/route/user.js';
import {useAppRoute} from './service/route/app.js';
import {useKbRoute} from './service/route/kb.js';
import {useSystemRoute} from './service/route/system.js';
import {useDashboardRoute} from "./service/route/dashboard.js";
import {logMiddleware} from "./service/middleware/common.js";
const app = express();
app.use(cors());
app.use(express.json());
app.use(express.static('dist'));
app.use(logMiddleware);
useUserRoute(app);
useAppRoute(app);
useKbRoute(app);
useSystemRoute(app);
useDashboardRoute(app);
app.get('/*', (req, res) => {
try {
res.sendFile(new URL('dist/index.html', import.meta.url).pathname);
} catch (error) {
res.end();
}
});
app.use((err, req, res, next) => {
try {
res.sendFile(new URL('dist/index.html', import.meta.url).pathname);
} catch (error) {
res.end();
}
});
const PORT = process.env.PORT || 3001;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});