-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
718 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Examples | ||
|
||
View working examples of `http-proxy-middleware` implemented in popular servers. | ||
|
||
To run and view the [examples](https://github.com/chimurai/http-proxy-middleware/tree/master/examples); Clone the `http-proxy-middleware` repo and install the dependencies: | ||
|
||
```bash | ||
$ git clone https://github.com/chimurai/http-proxy-middleware.git | ||
$ cd http-proxy-middleware | ||
$ npm install | ||
``` | ||
|
||
Run the example from root folder: | ||
|
||
```bash | ||
$ node examples/browser-sync | ||
``` | ||
|
||
```bash | ||
$ node examples/connect | ||
``` | ||
|
||
```bash | ||
$ node examples/express | ||
``` | ||
|
||
```bash | ||
$ node examples/websocket | ||
``` | ||
|
||
## Server recipes | ||
|
||
You can find more server implementations with `http-proxy-middleware` in the [server recipes](https://github.com/chimurai/http-proxy-middleware/tree/master/recipes/servers.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
var browserSync = require('../../node_modules/browser-sync/index').create(); // require('browser-sync').create(); | ||
var proxyMiddleware = require('../../index'); // require('http-proxy-middleware'); | ||
var browserSync = require('browser-sync').create(); | ||
var proxy = require('../../index'); // require('http-proxy-middleware'); | ||
|
||
// configure proxy middleware | ||
// context: '/' will proxy all requests | ||
// use: '/api' to proxy request when path starts with '/api' | ||
var proxy = proxyMiddleware('/api', { | ||
target: 'http://www.example.org', | ||
changeOrigin: true // for vhosted sites, changes host header to match to target's host | ||
}); | ||
/** | ||
* Configure proxy middleware | ||
*/ | ||
var chuckNorrisApiProxy = proxy('/jokes', { | ||
target: 'http://api.icndb.com', | ||
changeOrigin: true, // for vhosted sites, changes host header to match to target's host | ||
logLevel: 'debug' | ||
}); | ||
|
||
/** | ||
* Add the proxy to browser-sync | ||
*/ | ||
browserSync.init({ | ||
server: { | ||
baseDir: './', | ||
port: 3000, | ||
middleware: [proxy], // add the proxy to browser-sync | ||
middleware: [chuckNorrisApiProxy], | ||
}, | ||
startPath: '/api' | ||
startPath: '/jokes/random/5?limitTo=[nerdy]' | ||
}); | ||
|
||
console.log('listening on port 3000'); | ||
console.log('try:'); | ||
console.log(' http://localhost:3000/api'); | ||
console.log('[DEMO] Server: listening on port 3000'); | ||
console.log('[DEMO] Opening: http://localhost:3000/jokes/random/5?limitTo=[nerdy]'); |
Oops, something went wrong.