Created
June 19, 2019 04:27
-
-
Save xudaolong/20788c0a688562d4406c193cbc64f676 to your computer and use it in GitHub Desktop.
|-|&tag=Node
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 { 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