Giter VIP home page Giter VIP logo

Comments (8)

chimurai avatar chimurai commented on May 18, 2024 29

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.

thatisuday avatar thatisuday commented on May 18, 2024 12

Can we add a boolean option to plainly avoid path prefixing. pathRewrite still sound complex.

from http-proxy-middleware.

chimurai avatar chimurai commented on May 18, 2024

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.

chimurai avatar chimurai commented on May 18, 2024

Paths can be igored too:

proxyMiddleware(['/api/**', '!**/bad.json'], {target: 'http://test.com'}); //exclusion

from http-proxy-middleware.

maks-rafalko avatar maks-rafalko commented on May 18, 2024

@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.

maks-rafalko avatar maks-rafalko commented on May 18, 2024

This is exactly what I was looking for! Thank you, man.

from http-proxy-middleware.

chimurai avatar chimurai commented on May 18, 2024

Not all that "impossible" :)
Thanks for the question. This might be useful for users running into the same problem.

from http-proxy-middleware.

mike-aungsan avatar mike-aungsan commented on May 18, 2024

@chimurai

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.