forked from ionic-team/ionic-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
45 lines (36 loc) · 1.33 KB
/
app.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
var express = require("express"),
app = express(),
url = require('url'),
compress = require('compression'),
processRequest = require('./server/processRequest');
process.env.PWD = process.cwd()
console.log('PWD', process.env.PWD);
app.use(function(req, res, next) {
var parts = url.parse(req.url);
if (parts.path.indexOf('/blog/') == 0) {
res.redirect(301, 'http://blog.ionic.io/' + req.url.replace(/^\/blog\//, ''));
} else if (parts.path.indexOf('/creator/') == 0) {
res.redirect(301, 'https://creator.ionic.io/' + req.url.replace(/^\/creator\//, ''))
} else if (parts.path.indexOf('/tutorials') == 0) {
res.redirect(301, 'http://ionicframework.com/getting-started');
} else if (parts.path.indexOf('/jobs') == 0) {
res.redirect(301, 'http://ionic.io/jobs');
} else if (req.headers.host.indexOf('learn.') == 0) {
res.redirect(301, 'http://ionicframework.com/docs/');
} else {
next();
}
});
app.set('trust proxy', true);
app.use(compress());
app.use(processRequest);
app.use(express.static(process.env.PWD));
app.use(function(req, res, next) {
res.status(404);
res.sendFile(__dirname + '/404.html');
});
// bind the app to listen for connections on a specified port
var port = process.env.PORT || 3000;
app.listen(port);
// Render some console log output
console.log("Listening on port " + port);