This repository has been archived by the owner on Jun 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 71
/
server.js
67 lines (52 loc) · 1.75 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
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* Created by championswimmer on 24/11/16.
*/
const express = require('express');
const bodyParser = require('body-parser');
const forceSSL = require('express-force-ssl');
const config = require('./config.json');
const cors = require('cors');
const app = express();
app.set('forceSSLOptions', {
enable301Redirects: config.ENABLE_301_HTTPS_REDIRECT,
trustXFPHeader: config.TRUST_HTTPS_PROXY,
sslRequiredMessage: config.NON_HTTPS_REQUEST_ERRMSG
});
const shortner = require('./utils/shortner');
const expressGa = require('express-ga-middleware');
const route = {
api_v1: require('./routes/api_v1'),
shortcode: require('./routes/shortcode'),
auth: require('./routes/auth')
};
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.raw({
inflate: true,
limit: '100kb',
type: '*/*'
}));
const redirectToHome = function (req, res) {
res.redirect('http://codingblocks.com')
};
if (config.FORCE_HTTPS) {
app.use('/admin', forceSSL)
}
app.use('/admin', express.static(__dirname + "/static/admin"));
app.use('/.well-known', express.static(__dirname + "/.well-known"));
app.use(expressGa('UA-83327907-4'));
app.use('/api/v1', cors(), route.api_v1);
app.use('/', route.shortcode);
app.use('/auth', route.auth);
// Redirects the user to IDE home page if no ID is provided
app.get('/ide', (req, res) => {
res.redirect('http://ide.codingblocks.com');
})
// Redirects user to a particular place in IDE if he provides the ID
app.get('/ide/:id', (req, res) => {
res.redirect(`http://ide.codingblocks.com/#/s/${req.params.id}`);
});
app.use(redirectToHome);
app.listen( process.env.PORT || 4000, () => {
console.log("Listening on http://localhost:" + (process.env.PORT || "4000") + "/");
});