Skip to content

Instantly share code, notes, and snippets.

@xudaolong
Created June 19, 2019 04:27
Show Gist options
  • Save xudaolong/20788c0a688562d4406c193cbc64f676 to your computer and use it in GitHub Desktop.
Save xudaolong/20788c0a688562d4406c193cbc64f676 to your computer and use it in GitHub Desktop.
|-|&tag=Node
const { publicRuntimeConfig: { apiBase } } = require('../../shared/config/env')
const wreck = require('@hapi/wreck')
const h2o2 = require('@hapi/h2o2')
const proxy = [
['/v1/{p*}', apiBase],
['/v2/{p*}', apiBase]
]
const onResponse = async (err, res) => {
if (err) console.log(err.message)
return wreck.read(res, { json: true })
}
module.exports = async (server) => {
await server.register(h2o2)
proxy.forEach(([path, uri]) => {
server.route({
method: '*',
path,
handler: { proxy: { uri: `${uri}{path}`, onResponse } }
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment