Http-proxy-middleware: how can I shutdown proxy server?

Created on 8 Aug 2017  路  2Comments  路  Source: chimurai/http-proxy-middleware

I want to dynamic routing and need to shutdown the proxy server like this.

const express = require('express');
const proxy = require('http-proxy-middleware');
const app = express();

const proxies = {};
proxies["/foo"] = proxy({target: 'http://localhost:8010'});

app.use((req, res, next)=>{
  for(const path of Object.keys(proxies)){
    if(path === req.url.substr(0, path.length)){
      return proxies[path](req, res, next);
    }
  }
  return next();
});

setTimeout(()=>{
  // Suggestion: https://github.com/chimurai/http-proxy-middleware/blob/master/lib/index.js#L34
  // middleware.proxy = httpProxy.createProxyServer({});
  proxies["/foo"].proxy.close();
  delete proxies["foo"];
}, 10*1000);

But the current implementation cannot access raw proxy server and cannot close the server.

so I suggest to add middleware.proxy API.

All 2 comments

any news on this?

Since this is a question and not a bug report or feature request, post it to stack overflow instead of github issues.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gajus picture gajus  路  8Comments

udayms picture udayms  路  8Comments

mshindal picture mshindal  路  4Comments

ubreddy picture ubreddy  路  5Comments

DylanPiercey picture DylanPiercey  路  6Comments