|
|
@@ -0,0 +1,38 @@
|
|
|
+const express = require('express')
|
|
|
+const httpProxy = require('http-proxy')
|
|
|
+const request = require('request')
|
|
|
+
|
|
|
+const app = express()
|
|
|
+const assetsProxy = httpProxy.createProxyServer({
|
|
|
+ target: 'https://www.heroforge.com',
|
|
|
+ xfwd: false,
|
|
|
+ secure: false,
|
|
|
+ changeOrigin: true,
|
|
|
+ autoRewrite: true,
|
|
|
+ protocolRewrite: 'http',
|
|
|
+ selfHandleResponse: false
|
|
|
+})
|
|
|
+
|
|
|
+app.use(/^\/$/, (req, res) => {
|
|
|
+ request('https://www.heroforge.com', (err, response, body) => {
|
|
|
+ if (err) res.status(500).send(err)
|
|
|
+ else {
|
|
|
+ let html = body
|
|
|
+ .replace(/<script[^>]+googletagmanager.*<\/script>/g, '<!-- google tag manager -->')
|
|
|
+ .replace(/<img[^>]+facebook.*>/g, '<!-- facebook -->')
|
|
|
+ .replace('https://connect.facebook.net/en_US/fbevents.js', '')
|
|
|
+ .replace('</body>', '<script type="text/javascript" src="/custom/main.js"></script></body>')
|
|
|
+ res.status(200)
|
|
|
+ .set('Content-Type', 'text/html')
|
|
|
+ .send(html)
|
|
|
+ }
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+app.use('/custom/', express.static('./dist'))
|
|
|
+
|
|
|
+app.use('/', (req, res) => {
|
|
|
+ assetsProxy.web(req, res)
|
|
|
+})
|
|
|
+
|
|
|
+app.listen(9011)
|