-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
44 lines (39 loc) · 1.13 KB
/
app.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
import flash from 'connect-flash';
import cookie from 'cookie-parser';
import express from 'express';
import expressLayouts from 'express-ejs-layouts';
import session from 'express-session';
import methodOverride from 'method-override';
import morgan from 'morgan';
import { baseUrl, port } from './src/config/constants';
import todoRoutes from './src/routes/todo.route';
const app = express();
// Third Party Middlewares
app.use(morgan('dev'));
app.set('views', './src/views');
app.set('view engine', 'ejs');
app.use(expressLayouts);
app.use(methodOverride('_method'));
app.use(cookie('secret'));
app.use(session({
cookie: { maxAge: 60000,},
secret: 'secret',
resave: true,
saveUninitialized: true,
}));
app.use(flash());
// Express Middlewares
app.use(express.static('public'));
app.use(express.static('dist/public'));
app.use(express.urlencoded({ extended: true }));
// Connect to database
require('./src/config/database');
// Routes
todoRoutes(app);
app.use('*', (req, res) => {
res.status(404).send('404 Not Found!');
});
// Start server
app.listen(port, () => {
console.log(`Todo app is listening to ${baseUrl}`);
});