middleware/proxy

module:middleware/proxy

Description:
  • This middleware requires http-proxy package

    Routing globally

    Config

    middleware-proxy-path-blog.host.com = ^/blog/
    middleware-proxy-path-www.host.com = ^/products/
    

    One middleware for all

    const { api, middleware } = require("backendjs")
    
    api.app.use(middleware.proxy)
    

    Routing explicitly

    Separate middleware by route

     api.app.use("/blog/*", middleware.proxy.handle.bind({ host: "myhost.com" }))
    
     api.app.use("/internal/*", { host: "myhost.int", handle: middleware.proxy.handle })
    
Source:

Methods

(static) handle()

Description:
  • Web proxy middleware

Source:

(static) proxy(context, host)

Description:
  • Proxy middleware for a single host to use by explicit router

Source:
Parameters:
Name Type Description
context RequestContext
host string