Skip to content

Commit

Permalink
docs(example): fastify example (#1002)
Browse files Browse the repository at this point in the history
  • Loading branch information
chimurai committed May 12, 2024
1 parent f2a0af3 commit 465dd8a
Show file tree
Hide file tree
Showing 4 changed files with 444 additions and 35 deletions.
20 changes: 20 additions & 0 deletions examples/fastify/index.js
@@ -0,0 +1,20 @@
const fastify = require('fastify')({ logger: true });
const { createProxyMiddleware } = require('../../dist'); // require('http-proxy-middleware');

(async () => {
await fastify.register(require('@fastify/express'));

const proxy = createProxyMiddleware({
target: 'http://jsonplaceholder.typicode.com',
changeOrigin: true,
});

fastify.use(proxy);

fastify.listen({ port: 3000 }, (err, address) => {
if (err) throw err;
fastify.log.info(`server listening on ${address}`);

require('open')(`${address}/users`);
});
})();
4 changes: 3 additions & 1 deletion examples/package.json
Expand Up @@ -10,8 +10,10 @@
"author": "chimurai",
"license": "MIT",
"devDependencies": {
"@fastify/express": "3.0.0",
"browser-sync": "3.0.2",
"connect": "3.7.0",
"express": "4.19.2"
"express": "4.19.2",
"fastify": "4.27.0"
}
}

0 comments on commit 465dd8a

Please sign in to comment.