devbonzai 2.2.210 → 2.2.211
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/templates/handlers/proxy.js +34 -0
- package/templates/receiver.js +2 -0
package/package.json
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const http = require('http');
|
|
2
|
+
const { URL } = require('url');
|
|
3
|
+
|
|
4
|
+
function proxyHandler(req, res) {
|
|
5
|
+
// Target dev server (default localhost:3000, or pass ?target=...)
|
|
6
|
+
const target = req.query.target || 'http://localhost:3000';
|
|
7
|
+
// Path to fetch (default /)
|
|
8
|
+
const path = req.query.path || '/';
|
|
9
|
+
|
|
10
|
+
const fullUrl = new URL(path, target);
|
|
11
|
+
|
|
12
|
+
http.get(fullUrl.toString(), (proxyRes) => {
|
|
13
|
+
let body = '';
|
|
14
|
+
|
|
15
|
+
proxyRes.on('data', chunk => body += chunk);
|
|
16
|
+
proxyRes.on('end', () => {
|
|
17
|
+
const contentType = proxyRes.headers['content-type'] || '';
|
|
18
|
+
|
|
19
|
+
// Inject capture script into HTML
|
|
20
|
+
if (contentType.includes('text/html')) {
|
|
21
|
+
body = body.replace('</body>', '<script src="/bonzai-capture-client.js"></script></body>');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Forward content-type
|
|
25
|
+
res.set('Content-Type', contentType);
|
|
26
|
+
res.send(body);
|
|
27
|
+
});
|
|
28
|
+
}).on('error', (err) => {
|
|
29
|
+
res.status(502).send('Proxy error: ' + err.message);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = proxyHandler;
|
|
34
|
+
|
package/templates/receiver.js
CHANGED
|
@@ -22,6 +22,7 @@ const scanCodeQualityHandler = require('./handlers/scan_code_quality');
|
|
|
22
22
|
const scanStandardsHandler = require('./handlers/scan_standards');
|
|
23
23
|
const bonzaiCaptureClientHandler = require('./handlers/bonzai-capture-client');
|
|
24
24
|
const serveHandler = require('./handlers/serve');
|
|
25
|
+
const proxyHandler = require('./handlers/proxy');
|
|
25
26
|
|
|
26
27
|
const app = express();
|
|
27
28
|
|
|
@@ -47,6 +48,7 @@ app.post('/scan_code_quality', scanCodeQualityHandler);
|
|
|
47
48
|
app.post('/scan_standards', scanStandardsHandler);
|
|
48
49
|
app.get('/bonzai-capture-client.js', bonzaiCaptureClientHandler);
|
|
49
50
|
app.get('/serve', serveHandler);
|
|
51
|
+
app.get('/proxy', proxyHandler);
|
|
50
52
|
|
|
51
53
|
const port = 3001;
|
|
52
54
|
app.listen(port, () => {
|