-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.ts~HEAD
48 lines (41 loc) · 1.35 KB
/
server.ts~HEAD
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
import Express from 'express';
import next from 'next';
import morgan from 'morgan';
import cookieParser from 'cookie-parser';
import expressSession from 'express-session';
import dotenv from 'dotenv';
import path from 'path';
import { IncomingMessage, ServerResponse } from 'http';
const __Dev__ = process.env.NODE_ENV === 'development';
const app = next({ dev: __Dev__ });
const handle = app.getRequestHandler();
dotenv.config();
app.prepare().then(() => {
// NEXT와 EXPRESS를 연결해주는 코드
const server = Express();
server.use('/', Express.static(path.join(__dirname, 'public')));
server.use(morgan('dev'));
server.use(Express.json());
server.use(Express.urlencoded({ extended: true }));
server.use(cookieParser(process.env.COOKIE_SECRET));
server.use(
expressSession({
resave: false,
saveUninitialized: false,
secret: process.env.COOKIE_SECREçT,
cookie: {
httpOnly: true,
secure: false,
},
}),
);
server.get('/post/:postId', (req: Express.Request, res: Express.Response) => {
return app.render(req, res, '/post', { postId: req.params.postId });
});
server.get('*', (req: Express.Request, res: Express.Response) => {
return handle(req as IncomingMessage, res as ServerResponse);
});
server.listen(3060, () => {
console.log('next+express running on port 3060');
});
});