-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
81 lines (67 loc) · 2.29 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//Set up Express for handling routing
var express = require('express')
var app = express()
//Create locals for use during app
app.locals.moment = require('moment')
//Site Settings
var site = require('./site.json')
var utils = require('./utils.js')
//Set up pug as the view engine
app.set('view engine', 'pug')
//Home page
app.get('/', function (req, res) {
res.render('home', { site: site, title: 'Home', url: req.url })
})
//About Me page
app.get('/about', function (req, res) {
var languages = utils.getLanguages();
var tools = utils.getTools();
res.render('about', { site: site, title: 'About Me', url: req.url, langs: languages, tools: tools })
})
//About Me page
app.get('/cv', function (req, res) {
res.render('cv', { site: site, title: 'My CV', url: req.url })
})
//Projects page, displays all projects
app.get('/projects', function (req, res) {
//Go retreive the projects and their info.json
var projects = utils.getProjects();
res.render('projects', { site: site, title: 'My Projects', url: req.url, projects: projects });
})
//Directs to projects page
app.get('/projects/:pName', function (req, res, next) {
//Scan projects folder to get list of projects
var project = utils.getProject(req.params.pName);
if (project != undefined) {
res.render('project', { site: site, title: project.name, url: req.url, project: project })
return;
}
next();
})
//Static content handling
app.use('/css', express.static('public/css'));
app.use('/js', express.static('public/js'));
app.use('/fonts', express.static('public/fonts'));
app.use('/images', express.static('public/images'));
app.use('/files', express.static('public/files'));
//Some 404 handling
app.get("/*", function (req, res, next) {
res.status(404);
// respond with html page
if (req.accepts('html')) {
res.render('errors/404', { site: site, title: 'Error', url: req.url });
return;
}
// respond with json
if (req.accepts('json')) {
res.send({ error: 'Not found' });
return;
}
// default to plain-text. send()
res.type('txt').send('Not found');
});
//Set the app to listen
//TODO: change to better port, or use sockets
app.listen(9001, function () {
console.log('[Iainvm.tech] Portfolio app listening on port 9001')
})