-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
22 lines (18 loc) · 949 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var express = require("express"), proxy = require("express-http-proxy"), app = express();
app.use(express.static(__dirname)); // serve files in current directory
function getIpFromReq (req) { // get the client's IP address from request
var bareIP = ":" + ((req.connection.socket && req.connection.socket.remoteAddress)
|| req.headers["x-forwarded-for"] || req.connection.remoteAddress || "");
return (bareIP.match(/:([^:]+)$/) || [])[1] || "127.0.0.1";
}
// proxying requests from /analytics to www.google-analytics.com.
app.use("/analytics", proxy("www.google-analytics.com", {
proxyReqPathResolver: function (req) {
var url = req.url + (req.url.indexOf("?") === -1 ? "?" : "&")
+ "uip=" + encodeURIComponent(getIpFromReq(req));
console.log("Proxying www.google-analytics.com" + url);
return url;
}
}));
app.listen(1280);
console.log("Web application ready on http://localhost:1280");