-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
33 lines (25 loc) · 824 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
//NR - 'express' » NAME OF THE DEPENDENCIE
var express = require('express');
//Create app
var app = express();
const PORT = process.env.PORT || 3000;
//NOTA: ESTE CÓDIGO ESTÁ RELACIONADO COM EXPRESS E NÃO
//É FUNDAMENTAL PARA ESTE CURSO DE REACT;
//É UTILIZADO NO CONTEXTO DA PLATAFORMA HEROKU;
//Lec. 47 (Changes to use Heroku, from https to http),
//TEM DE ESTAR ANTES DOS RESTANTES ELEMENTOS ABAIXO;
app.use(function(req, res, next) {
if(req.headers['x-forwarded-proto'] === 'https') {
res.redirect('http://' + req.hostname + req.url);
} else {
next();
}
});
//.use() » ADD FUNCTIONALITY TO THE APPLICATION
//'public' » FOLDER TO BE EXPOSED TO THE SERVER
app.use(express.static('public'));
//START SERVER
app.listen(PORT, function ()
{
console.log('Express server is on port ' + PORT);
});