-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.ts
53 lines (45 loc) · 1.42 KB
/
handler.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
import serverless from 'serverless-http';
import express from 'express';
import cors from 'cors';
import morgan from 'morgan';
import dotenv from 'dotenv';
import cookieParser from 'cookie-parser';
import { authRouter, cardRouter, loginRouter, logoutRouter, artworkRouter } from './router';
import cookieUtil from '@/util/cookie';
dotenv.config();
const app = express();
const isDev = process.env.IS_OFFLINE;
const corsOrigin = isDev
? ['https://localhost:5173', 'http://localhost:5173']
: ['https://hyodee-card.surge.sh', /\.teamhh\.link$/];
app.use(
cors({
origin: corsOrigin,
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
preflightContinue: false,
optionsSuccessStatus: 204,
credentials: true,
allowedHeaders: ['Accept', 'Authorization', 'Content-Type', 'X-Requested-With', 'Range', 'baggage', 'sentry-trace'],
})
);
app.use(cookieParser());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(morgan(':method :url :status :res[content-length] - :response-time ms'));
app.use('/login', loginRouter);
app.use('/logout', logoutRouter);
app.use('/auth', authRouter);
app.use('/card', cardRouter);
app.use('/artwork', artworkRouter);
app.get('/', (_, res) => {
return res.status(200).json({
message: 'health check',
});
});
app.use((_, res) => {
cookieUtil.clear(res);
return res.status(404).json({
error: 'Not Found',
});
});
export const handler = serverless(app);