-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
84 lines (79 loc) · 2.86 KB
/
index.ts
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import AdminJSExpress from "@adminjs/express";
import * as AdminJSSequelize from "@adminjs/sequelize";
import AdminJS from "adminjs";
import cookieParser from "cookie-parser";
import cors from "cors";
import express, { json, urlencoded } from "express";
import path from "path";
import * as url from "url";
import { isRunOnDist, mode } from "./adminPage/components/index.js";
import { adminOptions, authProvider } from "./adminPage/index.js";
import { sequelize } from "./models/index.js";
import { initializeRedis } from "./redis/initialize.js";
import { alarmRouter, eventRouter, linktreeRouter, noticeRouter, userRouter } from "./routes/index.js";
const port = 7070;
const corsOptions = {
origin: mode == "production" ? "http://203.253.21.193:8080" : "http://localhost:8080",
credentials: true,
};
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
const app = express();
console.log({__dirname, css: path.join(__dirname, `./${isRunOnDist ? '../' : ''}adminPage/components/css`)});
// app.get('/', async (req, res) => res.sendFile(__dirname + '/test.html'));
// app.get('/login', (req, res) => res.sendFile(__dirname + '/testLogin.html'));
AdminJS.registerAdapter({
Resource: AdminJSSequelize.Resource,
Database: AdminJSSequelize.Database,
});
const start = async () => {
const admin = new AdminJS(adminOptions);
const adminRouter = mode == "development"
? AdminJSExpress.buildRouter(admin)
: AdminJSExpress.buildAuthenticatedRouter(
admin,
{
cookiePassword: "ss-cookie-pass",
provider: authProvider,
},
null,
{
secret: "test",
resave: false,
saveUninitialized: true,
}
);
// admin page router 설정
// const adminRouter = AdminJSExpress.buildRouter(admin);
// adminRouter 설정 전에 json, urlendcoded를 거치면 오류 발생함
app.use(
express.static(path.join(__dirname, `./${isRunOnDist ? '../' : ''}adminPage/components/css`))
);
app.use(express.static(path.join(__dirname + "/admin", `./${isRunOnDist ? '../' : ''}public`)));
app.use(express.static(path.join(__dirname, `./${isRunOnDist ? '../' : ''}public`)));
app.use(admin.options.rootPath, adminRouter);
app.use(cors(corsOptions));
app.use(cookieParser());
app.use(json());
app.use(urlencoded({ extended: false }));
app.use("/api", noticeRouter);
app.use("/api", userRouter);
app.use("/api", eventRouter);
app.use("/api", alarmRouter);
app.use("/api", linktreeRouter);
await sequelize
.authenticate()
.then(async () => {
console.log("sequelize connection success");
})
.catch((e) => {
console.log("sequelize error : ", e);
});
// 연결 test 및 게시글 캐싱
await initializeRedis();
app.listen(port, () => {
console.log(
`AdminJS started on http://localhost:${port}${admin.options.rootPath}`
);
});
};
start();