middleware-proxy
This is a simple tool that smooths the difficulties of working on integrated projects where the backend is hosted elsewhere from where you are developing your frontend. The proxy allows you to access your static HTML through a node server and redirect your RESTful calls to the implementing server.
usage
const proxy = ; /** * Returns a middleware function that selectively proxies incoming requests to another server. * * @param * @param * @param * * @return */`
basic express example
const express = ;const app = ;const http = ;const proxy = ; app; app; http;
This will send all requests starting with /service
to http://localhost:8080/service
.
budo (a browserify livereload solution)
usingconst proxy = ; 'index.js' browserify: debug: true host: '0.0.0.0' live: true open: true portfind: true pushstate: true serve: 'assets/bundle.js' stream: processstdout middleware: ;
removing an API prefix
Let's say your integration environment has chosen /api
as the mount point for communicating with your application's backend APIs. However, you're building your frontend in a separate project and can't easily run a dev server that joins both functionalities. middleware-proxy
solves this issue by allowing a third optional parameter that defines the part of the request URL to be stripped away when proxying the request to your destination host.
Assuming your remote development API host is at http://localhost:8080
and has a RESTful collection called /posts
, you would write your AJAX calls to GET
from /api/posts
and use the following configuration:
;
The request is transparently redirected behind the scenes:
GET /api/posts -> GET http://localhost:8080/posts
Based on the work in rgaskill/dev-rest-proxy