-
Notifications
You must be signed in to change notification settings - Fork 857
/
index.js
31 lines (24 loc) · 812 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* Module dependencies.
*/
const express = require('express');
const { createProxyMiddleware } = require('../../dist'); // require('http-proxy-middleware');
/**
* Configure proxy middleware
*/
const jsonPlaceholderProxy = createProxyMiddleware({
target: 'http://jsonplaceholder.typicode.com/users',
changeOrigin: true, // for vhosted sites, changes host header to match to target's host
logger: console,
});
const app = express();
/**
* Add the proxy to express
*/
app.use('/users', jsonPlaceholderProxy);
const server = app.listen(3000);
console.log('[DEMO] Server: listening on port 3000');
console.log('[DEMO] Opening: http://localhost:3000/users');
require('open')('http://localhost:3000/users');
process.on('SIGINT', () => server.close());
process.on('SIGTERM', () => server.close());