@arc-fusion/cli
Version:
CLI for running Arc Fusion on your local machine
28 lines (23 loc) • 830 B
JavaScript
const axios = require('axios')
/**
* proxyToFusion sends all non integration requests to Fusion origin
*/
const proxyToFusion = async (req, res) => {
try {
if (req?.originalUrl) {
const url = `http://origin:8080${req?.originalUrl}`
const fusionResponse = await axios({
method: req?.method,
url,
data: req?.body && Object.keys(req?.body)?.length !== 0 && req?.body
})
const contentType = fusionResponse?.headers?.['content-type']
contentType && res.setHeader('Content-Type', contentType)
return res.status(fusionResponse?.status).send(fusionResponse?.data)
}
} catch (error) {
console.error('INTEGRATION API ERROR: FUSION-PROXY-REQUEST')
return res.status(error?.response?.status).send(error?.response?.data)
}
}
module.exports = proxyToFusion