-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (38 loc) · 1012 Bytes
/
index.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
var express = require('express');
var config = require('./config');
var fs = require("fs");
var http = require("http");
var app = express();
app.use(express.static('public'));
app.get('/', function(req, res) {
var model = config.model;
res.render("index", { model: model });
});
app.get('/courses', function(req, res) {
var model = config.model;
res.render("courses", { model: model });
});
var pages = config.pages;
app.get(pages, function(req, res) {
var model = config.model;
model.error = {
url: req.url,
code: 401
};
res.status(401).render("error", { model: model });
});
app.use(function(req, res, next) {
var model = config.model;
model.error = {
url: req.url,
code: 404
};
res.status(404).render("error", { model: model });
});
app.set('views', __dirname + '/views/pages');
app.set('view engine', 'ejs');
var port = process.env.PORT || 5000;
var httpServer = http.createServer(app);
httpServer.listen(port, function() {
console.log("Listening at port " + port + ".");
});