This repository has been archived by the owner on Nov 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
54 lines (41 loc) · 1.48 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var express, http, sysPath, statik;
express = require('express');
sysPath = require('path');
http = require('http');
statik = require('statik');
if(process.env.PORT){
statik({
port: process.env.PORT
});
}else {
exports.startServer = function (port, path, callback) {
var app, server;
app = express();
if (process.env.PORT) {
console.log("Path recibido en Heroku:", path);
}
app.use(express.static(path));
require('./express/router')(app);
app.all("/", function (req, res) {
console.log("Entramos en ruta: /");
console.log("Ruta recibida:", req.url);
var filePath = sysPath.resolve(sysPath.join(path, 'index.html'));
return res.sendFile(filePath);
});
app.get("/docs*", function (req, res) {
return res.sendFile(sysPath.resolve(sysPath.join(path, "docs/index.html")));
});
app.all('/*', function (req, res) {
console.log("Entramos en ruta: /*");
console.log("Ruta recibida:", req.url);
var filePath = sysPath.resolve(sysPath.join(path, 'index.html'));
console.log("Ubicacion del fichero a retornar:", filePath);
return res.redirect('/');
});
server = http.createServer(app);
// Inicializacion alternativa en Heroku
port = process.env.port || port;
server.listen(parseInt(port, 10), callback);
return server;
};
}