-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
34 lines (25 loc) · 918 Bytes
/
server.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
var express = require('express');
var app = express();
var port = process.env.PORT || 5000;
var bodyParser = require('body-parser');
// makes it so `res.render` uses ejs to do its rendering
app.set('view engine', 'ejs');
// makes it so that files that are found in public/ are served
// before checking any of the other routes
app.use(express.static('public'));
// makes it so that forms that are POSTed will have
// the form data available as req.body
app.use(bodyParser.urlencoded());
app.get('/', function(req, res){
// renders views/index.ejs
res.render('index');
});
app.get('/dynamic/:value', function(req, res){
// This will be whatever was after the "/dynamic/" in the url.
// Example if the url is /dynamic/route, the value will be "route"
var value = req.params.value;
res.render('dynamic-route', {value:value});
});
app.listen(port, function(){
console.log('listening on ',port);
});