You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constexpress=require('express');constmorgan=require('morgan');constproxy=require('http-proxy-middleware');constngrok=require('ngrok');constcreateProxyMiddleware=proxy.createProxyMiddleware;constresponseInterceptor=proxy.responseInterceptor;constPORT=3000;constHOST='localhost';constTARGET_HOST=process.env.TARGET_HOST;(async()=>{constexternalUrl=awaitngrok.connect(PORT);constexternalHost=externalUrl.replace(/https?:\/\//,'');constapp=express();app.use(morgan('dev'));// Proxy everything.app.use('/',createProxyMiddleware({target: TARGET_HOST,changeOrigin: true,// Defer res.end() to be handled by responseInterceptor.selfHandleResponse: true,/** * Intercept response and replace Snopes URL with ngrok URL. * Remove integrity hashes from markup so static assets load. **/onProxyRes: responseInterceptor(async(responseBuffer)=>{returnresponseBuffer.toString('utf8')// Point Tachyon URLs at a web-accessible bucket..replace(/TARGET_HOST\/tachyon/ig,'LIVE_HOST/tachyon')// Everything else, rewrite so it will load that resource// over the ngrok connection..replace(/TARGET_HOST/ig,externalHost)// Remove integrity hashes entirely :( or things won't work..replace(/integrity=('[^']+'|"[^"]+")/ig,'');}),}));app.listen(PORT,HOST,()=>{console.log(`Starting local Proxy at ${HOST}:${PORT}`);console.log(`Local environment is now available at ${externalUrl}`);});})();
package.json:
{
"name": "local-server-proxy",
"private": true,
"version": "1.0.0",
"description": "Relay web traffic from an external URL to Local Server",
"main": "index.js",
"scripts": {
"proxy": "node server.js",
"start": "node server.js"
},
"author": "Human Made",
"license": "MIT",
"dependencies": {
"express": "^4.17.1",
"http-proxy-middleware": "^2.0.1",
"morgan": "^1.10.0",
"ngrok": "^4.1.0"
}
}
Acceptance criteria:
Create a containerised version of the above node app
Add a command called composer server share that starts the service
A SIGQUIT input should stop the service eg. ctrl+c
The text was updated successfully, but these errors were encountered:
We have a working proof of concept courtesy of @kadamwhite so far:
Instructions:
npm install
TARGET_HOST=dev.altis.dev npm start
while replacingdev.altis.dev
with your local env domainserver.js:
package.json:
Acceptance criteria:
composer server share
that starts the serviceThe text was updated successfully, but these errors were encountered: