-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (44 loc) · 1.46 KB
/
index.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
42
43
44
45
46
47
48
49
50
51
52
53
import { config } from "dotenv";
config()
import cors from "cors"
import express from "express";
import { getArticles } from "./server/libs/index.mjs"
import { SiteRouter, CompilerRouter } from "./server/express/routes/index.mjs"
import db from "./server/libs/db.mjs";
import { useSocket } from "./server/libs/socket.mjs";
import { dirname, join } from "path";
import { fileURLToPath } from "url"
import { publish, startRedis } from "./server/libs/redis.mjs";
const PORT = process.env.PORT || 3000;
export const prisma = db;
const app = express();
app.use(cors())
app.use(express.json())
app.use('/api/v1/sites', SiteRouter)
app.use('/api/v1/compile', CompilerRouter)
app.get('/api/v1/articles', (_req, res) => {
res.send(getArticles())
})
app.get('/api/v1', (_req, res) => {
res.send('Checker v1!')
})
const _dirname = typeof __dirname !== 'undefined'
? __dirname
: dirname(fileURLToPath(import.meta.url))
app.use('/react', express.static(`${_dirname}/dist/react`))
app.use('/react', (req, res, next) => {
if (/(.ico|.js|.css|.jpg|.png|.map)$/i.test(req.path)) {
next();
} else {
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
res.header('Expires', '-1');
res.header('Pragma', 'no-cache');
res.sendFile(join(_dirname, '/dist/react', 'index.html'));
}
});
const { getServer } = useSocket(app)
// startRedis()
const server = getServer()
server.listen(PORT, () => {
console.log(`Server started on port ${PORT}`);
})