forked from rht-labs/infographic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (42 loc) · 1.36 KB
/
index.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
const http = require('http');
const https = require('https');
const fs = require('fs');
const httpPort = process.env.INFOGRAPHIC_HTTP_PORT || 8080;
const httpsPort = process.env.INFOGRAPHIC_HTTPS_PORT || 8443;
const httpsKey = process.env.INFOGRAPHIC_HTTPS_KEY || '';
const httpsCert = process.env.INFOGRAPHIC_HTTPS_CERTIFICATE || '';
const websiteDir = process.env.INFOGRAPHIC_DIR || 'website';
var express = require('express');
var cors = require('cors');
var app = express();
var stack = require('./lib/stack');
var bodyParser = require('body-parser');
app.use(cors());
app.use(bodyParser());
app.use(express.static(websiteDir));
app.post('/stack', function (req, res) {
stack.processStack(req.body,function(err, response){
if (err){
// TODO: make the return status code be more specific per the error
// - i.e.: not use "400 Bad Request" for all of it
res.status(400).send(err);
} else {
res.send(response);
}
});
});
if (httpsCert.trim() && httpsKey.trim()) {
const options = {
key: fs.readFileSync(httpsKey),
cert: fs.readFileSync(httpsCert)
};
// Secure
https.createServer(options, app).listen(httpsPort, function () {
console.log('Listening on https://localhost:' + httpsPort);
});
} else {
// non-Secure
http.createServer(app).listen(httpPort, function() {
console.log('Listening on UNSECURE http://localhost:' + httpPort);
});
}