forked from Mittal-Analytics/Screener.in
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
45 lines (40 loc) · 1.04 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
"use strict";
/* global console */
var fs = require('fs');
var http = require('http');
var httpProxy = require('http-proxy');
function onError(e) {
console.log(e);
}
var options = {
autoRewrite: true,
changeOrigin: true,
target:'http://www.screener.in'
};
var proxy = httpProxy.createProxyServer(options);
proxy.on('error', onError);
http.createServer(function(req, res) {
console.log('URL:', req.url);
if(req.url == '/static/bundle.js.map') {
fs.readFile('./bundle.map.js', function(err, data) {
res.writeHead(200);
res.end(data);
});
} else if(req.url.startsWith('/static/bundle.')) {
fs.readFile('./bundle.js', function(err, data) {
res.writeHead(200);
res.end(data);
});
} else if(req.url.startsWith('/static/css/custom.')) {
fs.readFile('./custom.css', function(err, data) {
res.writeHead(200);
res.end(data);
});
} else {
proxy.web(req, res);
}
}).listen(8000);
console.log([
"Ready to accept requests.",
"Open: http://127.0.0.1:8000 in browser."
].join('\n'));