Closed nmehta6 closed 9 years ago
Found a package (connect-modrewrite) that allowed me to do this.
@nmehta6 how do you use connect-modrewrite in conjunction with node-proxy-middleware?
I want to add logic to ignore parts of URLs, for example
proxyOptions = url.parse(config.api)
proxyOptions.preserveHost = true
proxyOptions.route = '/api'
but when URL is /api/system
I want to ignore (skip) the proxy. That's only doable with a regex I guess. Any clues?
@binarykitchen I actually swapped out node-proxy-middleware with connect-modrewrite. Here is an example of how I am doing something similar. For these regex paths I am skipping the proxy and allowing the request to go through. https://github.com/CaryLandholt/fatarrow/blob/master/tasks/server/server.coffee#L28
Let me know if you need help translating the source from CoffeeScript to js.
hmmm, i tried but doesn't work well for me. here the config:
PROXY_CONFIG = [
"^/api/$ #{config.api} [P, L]"
]
PROXY_EXCLUSIONS = [
'^/api/system/motd*$ - [L]'
]
modRewriteConfig = PROXY_CONFIG.concat(PROXY_EXCLUSIONS)
console.log(modRewriteConfig)
shows
[ '^/api/$ http://localhost:8181/api [P, L]',
'^/api/system/motd*$ - [L]' ]
i want all api calls to be redirected to port 8181, for example http://localhost:3000/api/login
should become http://localhost:8181/api/login
except /api/system/motd_23423432.html
shouldnt get redirected.
any clues what i am doing wrong here?
I believe you have the wrong order here. First line in the config array will proxy everything.
It would be nice to be able to use patterns for URLs so that this proxy is a little more flexible. Instead of string comparison, minimatch can be used.