-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
29 lines (21 loc) · 760 Bytes
/
app.js
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
const path = require('path');
const express = require('express');
const blogRoutes = require('./routes/blog');
const db = require('./data/database');
const app = express();
// Activate EJS view engine
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use(express.urlencoded({ extended: true })); // Parse incoming request bodies
app.use(express.json());
app.use(express.static('public')); // Serve static files (e.g. CSS files)
app.use(blogRoutes);
app.use(function (error, req, res, next) {
// Default error handling function
// Will become active whenever any route / middleware crashes
console.log(error);
res.status(500).render('500');
});
db.connectToDatabase().then(function () {
app.listen(3000);
});