Skip to content

Instantly share code, notes, and snippets.

@timoweiss
Created January 25, 2018 13:33
Show Gist options
  • Save timoweiss/fc6e9d51191ac1e9ac862a5aa3a23622 to your computer and use it in GitHub Desktop.
Save timoweiss/fc6e9d51191ac1e9ac862a5aa3a23622 to your computer and use it in GitHub Desktop.
proxy
{
"name": "proxy",
"version": "1.0.0",
"description": "",
"main": "server.js",
"author": "",
"license": "ISC",
"dependencies": {
"h2o2": "^7.0.0",
"hapi": "^17.1.1"
}
}
const Hapi = require('hapi');
const h2o2 = require('h2o2');
const server = new Hapi.server({
port: 3333,
routes: {
cors: true,
},
});
async function startProxy() {
try {
await server.register({ plugin: h2o2 });
server.route({
method: '*',
// register for all paths
path: '/{param*}',
handler: {
proxy: {
async mapUri(request) {
const originalPath = request.raw.req.url;
const upstreamUrl = `https://localhost:8080${originalPath}`;
return {
uri: upstreamUrl,
};
},
},
},
});
await server.start();
console.log('Server started at:', server.info.uri);
} catch (error) {
console.error(error);
}
}
startProxy();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment