-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
37 lines (28 loc) · 1.17 KB
/
server.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
import express from 'express';
import logger from 'morgan';
import cors from 'cors';
import { Sequelize } from 'sequelize';
import config from './server-config';
import dbconfig from './db-config';
import AuthRoute from './controllers/auth.controller';
import PostRoute from './controllers/post.controller';
import BookmarkRoute from './controllers/bookmark.controller';
const app: express.Application = express();
const env = process.env.NODE_ENV || 'development';
const sequelize = new Sequelize(dbconfig[env].database, dbconfig[env].username, dbconfig[env].password, dbconfig[env]);
sequelize.sync();
app.use(logger(config.env));
app.disable('x-powered-by');
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(config.staticDir));
app.use('/api/auth', AuthRoute);
app.use('/api/post', PostRoute);
app.use('/api/bookmark', BookmarkRoute);
app.use('/static', express.static(config.fileDir.default));
app.use('/', express.static(config.viewsDir));
app.use('*', (req, res) => res.redirect("http://recipeapp.saintdev.kr/"));
app.listen(config.port, (): void => {
console.log(`Listening at http://localhost:${config.port}/`);
});