jkyberneees / fastify-gateway Goto Github PK
View Code? Open in Web Editor NEWA Node.js API gateway that just works!
Home Page: https://www.npmjs.com/package/k-fastify-gateway
License: MIT License
A Node.js API gateway that just works!
Home Page: https://www.npmjs.com/package/k-fastify-gateway
License: MIT License
Hello,
what is the purpose of 'shouldAbortProxy' in :
https://github.com/jkyberneees/fastify-gateway/blob/master/index.js#L6-L8 ?
Thanks
I'm looking for a gateway for nodejs / typescript that allows me handle vaeious concerns not directly related to microservices for instance authentication, authorization etc.
i see that it's been a long time there has been no activity happening. i want to know if it is stable enough to be used in production or was it just a gateway experiment.
there is express-gateway also but it has also been abondoned a long time ago
When I proxy a request and the target immediately returns a 200 or a 404 (no work) the request doesn't take much longer than without the proxy.
When I proxy a request where the target returns a 204 (with no work, immediately reply, and some other status codes) it always takes at least 5+ seconds.
When I don't proxy a request where the target returns a 204 (no work, immediate reply) it takes a few milliseconds. This is the same for all other status codes with no proxy and immediate reply (no work).
Not sure this is a gateway issue but all projects I'm proxing against are using fastify, the test project I tested against is literally a single file with dumb routes/handlers which immediately return a code and response.
Any help would be great! Want to return an appropriate status code.
When I proxy requests to a domain eg: http://localhost/mydir
it returns a 404. Is there anything I'm doing wrong? In this case my prefix is myproxy
.
It would be nice to also have the possibility to define http methods for routes, like
{
prefix: '/public',
prefixRewrite: '',
target: 'http://localhost:3000',
methods: ['GET']
}
I am trying to send a post request by it returns an error saying "Unsupported Media Type" . What could I be doing wrong ?
Running npm audit
on a fresh install of fastify-gateway results in a found 1 critical severity vulnerability
resolved in fastify-reply-from >=4.0.2.
I can prepare a PR if you are still working on this project.
Thanks
Why is the proxy overwriting the HTTP_HOST port ?
Hello,
it could be good if we could declare the "rate-limit" directly from the route declaration.
it could a optional parameter set to false by default if not use.
Thanks
Thank you for this amazing library. I have two concerns. First is how do I map a path of my gateway to a totally different prefix in my service. Second, how do I specify path parameters?
While accessing http://127.0.0.1:8080/{abc} POST route with request.content-type = 'multipart/form-data'
Port Exposed: 8080
POST /api/-------------route--------------- HTTP/1.1
Host: 127.0.0.1:8080
Connection: keep-alive
Content-Length: 412
Accept: application/json, text/plain, /
enctype: multipart/form-data
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryAjpQdkhEmREOaAiB
Origin: http://127.0.0.1:8080
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Referer: http://127.0.0.1:8080/-route-
Accept-Encoding: gzip, deflate, br
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8
Cookie: ------------cookie----------
Cause error with status code: 415 Unsupported Media Type
FST_ERR_CTP_INVALID_MEDIA_TYPE: Unsupported Media Type: multipart/form-data; boundary=----WebKitFormBoundaryDtgoTu7ABM7JcOnz
How do I make aggregated requests ?
When the trailing slash is present in my url , it works fine . The moment its gone ,404 . Possible bug ?
Hello, first thanks for the amazing library. π
Is there any way to access the response body payload in the onResponse
hook? If yes, how?
I think it will be better from an architectural standpoint to give services endpoints with each service having its own configuration . Then instead of assigning endpoints in each route we can assign service name as key . Also it'd be great if we can have the provision for flexible service endpoints which will get rid of the 1:1 mapping and make the gateway more robust . Any thoughts ? :)
Hi,
I dont know if I am doing it right, but when I try to access any route, the gateway always returns 404 (not found). My code is this:
const gateway = require('fastify')({})
gateway.register(require('fastify-reply-from'))
gateway.register(require('k-fastify-gateway'), {
middlewares: [
require('cors')(), // https://www.npmjs.com/package/cors
require('helmet')() // https://helmetjs.github.io/
],
routes: [{
prefix: '/gmail',
prefixRewrite: '',
target: 'https://www.google.com',
middlewares: [],
hooks: {
// onResponse (res, reply) { reply.send(res) }
// async onRequest (req, reply) {},
onResponse (res, reply) { reply.send(res) }
}
},
{
prefix: '/admin',
prefixRewrite: '',
target: 'https://www.google.com',
middlewares: [],
hooks: {
onResponse (res, reply) { reply.send(res) }
}
}]
})
// start the gateway HTTP server
gateway.listen(8080).then((address) => {
console.log(API Gateway listening on ${address}
)
})
I'm trying to proxy the /logout url to my api server, but I think fastify-gateway does prefix + '/*'
at which point /logout doesn't match anymore.
log error
{"level":30,"time":1685823837047,"pid":41165,"hostname":"Andis-MacBook-Pro.local","reqId":"req-1","req":{"method":"GET","url":"/health/time","hostname":"localhost:3001","remoteAddress":"::1","remotePort":53825},"msg":"incoming request"}
{"level":50,"time":1685823837048,"pid":41165,"hostname":"Andis-MacBook-Pro.local","reqId":"req-1","req":{"method":"GET","url":"/health/time","hostname":"localhost:3001","remoteAddress":"::1","remotePort":53825},"res":{"statusCode":500},"err":{"type":"TypeError","message":"Cannot read properties of undefined (reading 'url')","stack":"TypeError: Cannot read properties of undefined (reading 'url')\n at Object. (/Users/andi-dans/Dans/Labs/nx-fastify-microservice-base/node_modules/k-fastify-gateway/index.js:6:35)\n at preHandlerCallback (/Users/andi-dans/Dans/Labs/nx-fastify-microservice-base/node_modules/fastify/lib/handleRequest.js:128:37)\n at preValidationCallback (/Users/andi-dans/Dans/Labs/nx-fastify-microservice-base/node_modules/fastify/lib/handleRequest.js:112:5)\n at handler (/Users/andi-dans/Dans/Labs/nx-fastify-microservice-base/node_modules/fastify/lib/handleRequest.js:76:7)\n at handleRequest (/Users/andi-dans/Dans/Labs/nx-fastify-microservice-base/node_modules/fastify/lib/handleRequest.js:24:5)\n at runPreParsing (/Users/andi-dans/Dans/Labs/nx-fastify-microservice-base/node_modules/fastify/lib/route.js:537:5)\n at Object.routeHandler [as handler] (/Users/andi-dans/Dans/Labs/nx-fastify-microservice-base/node_modules/fastify/lib/route.js:484:7)\n at Router.callHandler (/Users/andi-dans/Dans/Labs/nx-fastify-microservice-base/node_modules/find-my-way/index.js:398:14)\n at Router.lookup (/Users/andi-dans/Dans/Labs/nx-fastify-microservice-base/node_modules/find-my-way/index.js:376:17)\n at Server.preRouting (/Users/andi-dans/Dans/Labs/nx-fastify-microservice-base/node_modules/fastify/fastify.js:792:14)"},"msg":"Cannot read properties of undefined (reading 'url')"}
{"level":30,"time":1685823837056,"pid":41165,"hostname":"Andis-MacBook-Pro.local","reqId":"req-1","res":{"statusCode":500},"responseTime":8.463874999433756,"msg":"request completed"}
3.3.0
to 3.4.0
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
supertest is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 14 commits.
5640ac9
3.4.0
60f8a9e
Merge pull request #532 from visionmedia/v3.4.0
43bfae1
doc(History.md) changelog updated
fc1568d
doc(README.md) cookie example added
3192d96
chore(package-lock.json) file updated
b3d271f
chore(package.json) blocks reorganized, nock removed
aeae0f3
chore(.travis.yml) pipeline more explicit
53feddc
chore(test/supertest.js) obscure test removed
50c59d6
Merge pull request #519 from oprogramador/patch-3
6ca3897
Merge pull request #517 from oprogramador/patch-2
0146d81
auth info in README
d853b37
fix typo in README
8158979
Merge pull request #513 from rubendg/use-isarray
550613b
Use more robust Array instance check
See the full diff
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.