-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
54 lines (45 loc) · 1.4 KB
/
Copy pathapp.js
File metadata and controls
54 lines (45 loc) · 1.4 KB
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
import express from 'express';
import 'express-async-errors';
import cors from 'cors';
import morgan from 'morgan';
import helmet from 'helmet';
import cron from 'node-cron';
import http from 'http';
import authRouter from './routers/auth.js';
import waffleCardRouter from './routers/waffleCard.js';
import commentRouter from './routers/comment.js';
import likeRouter from './routers/like.js';
import { config } from './config.js';
import { connectDB } from './database/database.js';
const app = express();
const corsOptions = {
origin: config.cors.allowedOrigin,
optionSuccess: 200,
};
app.use(express.json());
app.use(helmet());
app.use(cors(corsOptions));
app.use(morgan('tiny'));
app.get('/', (req, res) => {
res.status(200).json({ author: '정윤호', message: 'Welcome to waffleCard!' });
});
app.use('/auth', authRouter);
app.use('/waffle-cards', waffleCardRouter);
app.use('/comments', commentRouter);
app.use('/likes', likeRouter);
app.use((req, res) => {
res.status(404).json({ message: 'Not Found' });
});
app.use((error, req, res) => {
console.error(error);
res.status(500).json({ message: 'Internal Server Error' });
});
connectDB().then(() => {
console.log(`Server is started... ${new Date()}`);
app.listen(config.port);
});
// 헤로쿠 서버 잠들기 방지
cron.schedule('*/20 23,0-14 * * *', () => {
http.get('http://waffle-card.herokuapp.com');
console.log('wake up!', new Date());
});