-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
24 lines (21 loc) · 728 Bytes
/
server.js
File metadata and controls
24 lines (21 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
var express = require('express');
//create our app
var app = express();
const PORT = process.env.PORT || 3000;
app.use(function(req, res, next){
if (req.headers['x-forwarded-proto'] === 'https') {
res.redirect('http://' + req.hostname + req.url)
} else {
next();
}
})
//tell it which folder to serve
//app.use lets you add functionality to express app
//call express.static
//express.static is going to specify a folder name that we want to expose to the web server
app.use(express.static('public'));
//start the server
//app.listen takes two arguments - the port and a function which will get called once the server is up
app.listen(PORT, function() {
console.log('Express server is up on port ' + PORT);
})