-
Notifications
You must be signed in to change notification settings - Fork 879
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (26 loc) · 805 Bytes
/
index.js
File metadata and controls
34 lines (26 loc) · 805 Bytes
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
32
33
34
// @ts-check
/**
* Module dependencies.
*/
import express from 'express';
import open from 'open';
import { createProxyMiddleware } from '#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');
open('http://localhost:3000/users');
process.on('SIGINT', () => server.close());
process.on('SIGTERM', () => server.close());