Skip to content

Commit 465dd8a

Browse files
authored
docs(example): fastify example (#1002)
1 parent f2a0af3 commit 465dd8a

File tree

4 files changed

+444
-35
lines changed

4 files changed

+444
-35
lines changed

examples/fastify/index.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const fastify = require('fastify')({ logger: true });
2+
const { createProxyMiddleware } = require('../../dist'); // require('http-proxy-middleware');
3+
4+
(async () => {
5+
await fastify.register(require('@fastify/express'));
6+
7+
const proxy = createProxyMiddleware({
8+
target: 'http://jsonplaceholder.typicode.com',
9+
changeOrigin: true,
10+
});
11+
12+
fastify.use(proxy);
13+
14+
fastify.listen({ port: 3000 }, (err, address) => {
15+
if (err) throw err;
16+
fastify.log.info(`server listening on ${address}`);
17+
18+
require('open')(`${address}/users`);
19+
});
20+
})();

examples/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
"author": "chimurai",
1111
"license": "MIT",
1212
"devDependencies": {
13+
"@fastify/express": "3.0.0",
1314
"browser-sync": "3.0.2",
1415
"connect": "3.7.0",
15-
"express": "4.19.2"
16+
"express": "4.19.2",
17+
"fastify": "4.27.0"
1618
}
1719
}

0 commit comments

Comments
 (0)