-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
25 lines (23 loc) · 792 Bytes
/
server.js
File metadata and controls
25 lines (23 loc) · 792 Bytes
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
var express = require('express');
var app = express();
var request = require("request");
app.get('*', function(req, res) {
var fetchURL = "http://your-origin-server-goes-here";
var nonoriginURL = "https://the-endpoint-that-the-user-sees";
if (req.originalUrl != undefined) {
var rewriteURL = fetchURL + req.originalUrl;
} else {
var rewriteURL = fetchURL;
}
console.log(rewriteURL);
if (rewriteURL.indexOf("jpg") == -1 && rewriteURL.indexOf("png") == -1 || rewriteURL.indexOf("woff") != -1) {
request({
"method": "GET",
"uri": rewriteURL
}).pipe(res);
} else {
console.log("Redirect (" + req.originalUrl + ")");
res.redirect(nonoriginURL + req.originalUrl);
}
});
app.listen(3000);