-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
53 lines (47 loc) · 1.3 KB
/
server.js
File metadata and controls
53 lines (47 loc) · 1.3 KB
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
var express = require("express");
var app = express();
var http = require('http')
var config = require('./config');
/******************************
* APIs - Proxy to Gateway API
*******************************/
app.all("/api/:cmd", function (request, response) {
// Proxy the API request to the test stand
try {
var options = {
host: config.api.host,
path: config.api.path + request.params.cmd,
method: request.method,
headers: {
"Content-Type" : "application/json"
}
};
console.log(options);
var demo_req = http.request(options, function(demo_res) {
var str = '';
demo_res.on('data', function(chunk) {
str += chunk;
});
demo_res.on('end', function() {
response.status(demo_res.statusCode).send(str);
});
}).on('error', function(e) {
console.log(e);
var statusCode = e.statusCode;
if (!statusCode) {
statusCode = 404;
}
response.status(statusCode).send(e);
});
demo_req.end();
} catch (err) { console.log(err); }
});
/**************
* Views
***************/
//serve static file (index.html, images, css)
app.use(express.static(__dirname + '/public'));
var port = process.env.PORT || 3000;
app.listen(port, function() {
console.log('App started on port:' + port);
});