1 | /**
|
2 | * Module dependencies.
|
3 | */
|
4 | var express = require('express');
|
5 | var proxy = require('../../index'); // require('http-proxy-middleware');
|
6 |
|
7 | /**
|
8 | * Configure proxy middleware
|
9 | */
|
10 | var jsonPlaceholderProxy = proxy({
|
11 | target: 'http://jsonplaceholder.typicode.com',
|
12 | changeOrigin: true, // for vhosted sites, changes host header to match to target's host
|
13 | logLevel: 'debug'
|
14 | });
|
15 |
|
16 | var app = express();
|
17 |
|
18 | /**
|
19 | * Add the proxy to express
|
20 | */
|
21 | app.use('/users', jsonPlaceholderProxy);
|
22 |
|
23 | app.listen(3000);
|
24 |
|
25 | console.log('[DEMO] Server: listening on port 3000');
|
26 | console.log('[DEMO] Opening: http://localhost:3000/users');
|
27 |
|
28 | require('opn')('http://localhost:3000/users');
|