-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
45 lines (35 loc) · 1022 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//IMPORTS
const express = require('express');
const data = require('./data.json');
const projectData = data.projects;
//CONSTANTS
const app = express();
const port = process.env.PORT || 3000;
//SETTINGS
app.set('view engine','pug');
//ROUTE STATIC FILES
app.use('/static', express.static('public'));
app.use('/static', express.static('images'));
//ROUTE PAGE TEMPLATES
app.get('/', function (req, res) {
res.render('index', { projects: projectData });
});
app.get('/about', function (req, res) {
res.render('about')
});
app.get('/project/:id', function (req, res) {
res.render('project', { projects: projectData[req.params.id] })
});
//HANDLE ERRORS
app.get('*', function(req, res, next) {
let err = new Error('Page Not Found');
err.statusCode = 404;
next(err);
});
app.use((err, req, res, next) => {
res.locals.error = err;
res.status(err.status || 500);
console.log(err.message);
res.render('error', err);
});
app.listen(port, () => console.log(`App listening on port ${port}!`))