Comments (8)
Ah, didn't read your question well... :)
You can rewrite paths with the pathRewrite
option.
https://www.npmjs.com/package/http-proxy-middleware#options
var options = {
target: 'http://test.com',
changeOrigin: true,
pathRewrite: {'^/api' : ''} // <-- this will remove the /api prefix
};
server.middleware = proxyMiddleware('/api', options);
from http-proxy-middleware.
Can we add a boolean
option to plainly avoid path prefixing. pathRewrite
still sound complex.
from http-proxy-middleware.
Did you try the wildcard/globbing configuration?
https://www.npmjs.com/package/http-proxy-middleware#context-matching
It should give you the full control on which paths should be proxied or not.
server.middleware = proxyMiddleware('/api/**', {target: 'http://test.com', changeOrigin: true});
Wildcards/globbing is introduced in v0.3.0
from http-proxy-middleware.
Paths can be igored too:
proxyMiddleware(['/api/**', '!**/bad.json'], {target: 'http://test.com'}); //exclusion
from http-proxy-middleware.
@chimurai with this configuration
server.middleware = proxyMiddleware('/api/**', {target: 'http://test.com', changeOrigin: true});
when I call $http.get('/api/users')
request is proxied to http://test.com/api/users
, but I need http://test.com/users
(without prefix /api
in the target URL)
from http-proxy-middleware.
This is exactly what I was looking for! Thank you, man.
from http-proxy-middleware.
Not all that "impossible" :)
Thanks for the question. This might be useful for users running into the same problem.
from http-proxy-middleware.
Need to improve documentation and more example.
var httpProxyMiddleware = require('http-proxy-middleware');
var abcProxy = httpProxyMiddleware({
target: 'http://localhost:8443',
changeOrigin: false, // for vhosted sites, changes host header to match to target's host
pathRewrite: {
"^/abc" : "" // rewrite path
},
logLevel: 'debug'
});
// Add the proxy to express
//app.use(abcProxy);
app.use('/abc', abcProxy);
I have to put forward slash, and this work: http://localhost:3000/abc/
But without forward slash, it does not work. http://localhost:3000/abc
from http-proxy-middleware.
Related Issues (20)
- req.url is always '/' HOT 4
- Fails to proxy from localhost to localhost HOT 2
- Too many subscriptions to Server.close event cause a OOM? HOT 4
- TS type compatibility HOT 4
- ERR_HTTP_HEADERS_SENT from onProxyReq with https-proxy-agent HOT 2
- Proxy to another proxy HOT 1
- Security Vulnerability in Dependency | follow-redirects HOT 2
- "Invalid context" error message is unhelpful when mixing paths with globs HOT 1
- Release plan for v3.0.0 HOT 1
- Response interceptor copyHeaders logic only removes first character of cookie domain because of non-greedy regex
- TypeError: (options.buffer || req).pipe is not a function HOT 1
- Allow custom Http Method like LIST HOT 3
- SSE close connection issue with proxy HOT 3
- V3: base path not stripped from WebSocket upgrade requests HOT 2
- SSL Error in when Upgrading from node 16 to 18 HOT 3
- Setting followRedirects to true limits the form-data body size length to 10 MB
- Removes port from target HOT 9
- Hono Support for http-proxy-middleware HOT 1
- The Cookie header is not being included in the redirected address. HOT 2
- How to reduce logger to only errors? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from http-proxy-middleware.