-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (27 loc) · 890 Bytes
/
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
var express = require('express');
var httpProxy = require('http-proxy');
var bodyParser = require('body-parser');
var apiForwardingUrl = 'https://api.coursera.org';
var proxyOptions = {
changeOrigin: true
};
httpProxy.prototype.onError = function (err) {
console.log(err);
};
var apiProxy = httpProxy.createProxyServer(proxyOptions);
console.log('Forwarding API requests to ' + apiForwardingUrl);
// Node express server setup.
var server = express();
server.set('port', (process.env.PORT || 3000));
server.use(express.static(__dirname ));
server.all("/api/*", function(req, res) {
apiProxy.web(req, res, {target: apiForwardingUrl});
});
server.use(bodyParser.json());
server.use(bodyParser.urlencoded({
extended: true
}));
// Start Server.
server.listen(server.get('port'), function() {
console.log('Express server listening on port ' + server.get('port'));
});