Created
January 25, 2018 13:33
-
-
Save timoweiss/fc6e9d51191ac1e9ac862a5aa3a23622 to your computer and use it in GitHub Desktop.
proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "proxy", | |
"version": "1.0.0", | |
"description": "", | |
"main": "server.js", | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"h2o2": "^7.0.0", | |
"hapi": "^17.1.1" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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