Yes
For some routes, I just want them to return a 404, and I don't want to proxy them anywhere. I'm able to accomplish this using onProxyReq like so:
proxy('/route', {
target: 'https://localhost/', // target is ignored since we always send 404s
onProxyReq: (proxyReq, req, res) => { res.status(404).send(); }
}));
For these routes, the target really is irrelevant - there's no place I'm trying to proxy them to. But, I have to include a target in the config, or else I'll get the following error:
[HPM] Missing "target" option. Example: {target: "http://www.example.org"}
Maybe target should be optional, and the message above could be a warning instead of an error.
In the use-case you describe; the whole proxy is not needed right?
With just express middleware:
app.use('/route', (req, res, next) => {
res.status(404).send();
})
instead of:
app.use(proxy('/route', {
target: 'https://localhost/', // target is ignored since we always send 404s
onProxyReq: (proxyReq, req, res) => { res.status(404).send(); }
}));
)
Yeah you're absolutely right! Closing.
its still relevant when using custom router.. in this case no need "target"
@chimurai could we maybe reconsider making target optional? Just stumbled upon this when using the router option to dynamically determine the target.
Most helpful comment
its still relevant when using custom router.. in this case no need "target"