Comments (6)
Hi @parthibd, would you please describe more details about the gateway configuration and the request you are making?
Thanks and Regards
from fastify-gateway.
var jwt = require('jsonwebtoken');
require('dotenv').config();
const fastify = require('fastify')({
logger: true
});
const jwtExceptionUrls = [
`${process.env.ENDPOINT1_PREFIX}/api/login`,
".jpg",
".jpeg",
".bmp",
".gif",
".png"
];
function checkExceptionUrls(url) {
for (let exceptionUrl of jwtExceptionUrls) {
if (url.endsWith(exceptionUrl))
return true;
}
return false;
}
const checkJwtTokenMiddleware = function (req, res, next) {
if (checkExceptionUrls(req.url)) {
next();
} else {
let token = null;
if (req.headers.authorization == null) {
res.setHeader('Content-Type', 'application/json');
res.statusCode = 401;
res.end(JSON.stringify({error: "Token missing in header.Please specify"}));
} else if (req.headers.authorization.startsWith('Bearer ')) {
token = req.headers.authorization.slice(7, req.headers.authorization.length).trim();
try {
jwt.verify(token, process.env.JWT_SECRET);
next()
} catch (err) {
res.setHeader('Content-Type', 'application/json');
res.statusCode = 401;
res.end(JSON.stringify({error: err.message}));
}
} else {
res.setHeader('Content-Type', 'application/json');
res.statusCode = 401;
res.end(JSON.stringify({error: "Token missing in header"}));
}
}
};
fastify.register(require('fastify-reply-from'));
fastify.register(require('k-fastify-gateway'), {
middlewares: [
require('cors')(),
require('helmet')(),
checkJwtTokenMiddleware
],
routes: [
{
prefix: process.env.ENDPOINT2_PREFIX,
target: process.env.ENDPOINT2,
middlewares: []
},
{
prefix: process.env.ENDPOINT3_PREFIX,
target: process.env.ENDPOINT3,
middlewares: [],
},
{
prefix: process.env.ENDPOINT1_PREFIX,
target: process.env.ENDPOINT1,
middlewares: [],
},
]
});
fastify.listen(process.env.GATEWAY_LISTEN_PORT, '0.0.0.0').then((address) => {
console.log(`API Gateway listening on ${address}`)
});
from fastify-gateway.
This is the code . Now say I am making a POST request to http://localhost:8090/endpoint1_prefix/api/photo
as a multipart request , fastify returns that unidentified body type . What could I be doing wrong ?
from fastify-gateway.
Hi @parthibd, I think this thread will be of your help: fastify/fastify#202
Thanks and Regards
from fastify-gateway.
I tried this solution, but it does not work.
from fastify-gateway.
This issue is related to fastify, meaning is not being originated by this module.
I may recommend you to have a look at this other alternative I have created: https://www.npmjs.com/package/fast-gateway
It is faster, and not bound to fastify.
More details also here: https://thejs.blog/2019/07/04/node-js-api-gateway-a-developer-perspective/
from fastify-gateway.
Related Issues (19)
- 5+ seconds response on some status codes < 200ms on others HOT 5
- http methods HOT 1
- feature : HOT 13
- Path parameters? HOT 6
- Aggregated request? HOT 12
- Trailing slash problem HOT 3
- Service groupings ? HOT 6
- Proxying requests to a domain with a subdirectory HOT 1
- what is shouldAbortProxy in the proxy function ? HOT 1
- Not Found HOT 8
- Prefix + /* doesn't allow for top level routes HOT 6
- HTTP_HOST being overwritten
- An in-range update of supertest is breaking the build 🚨 HOT 2
- FST_ERR_CTP_INVALID_MEDIA_TYPE: Unsupported Media Type: multipart/form-data; boundary=----WebKitFormBoundaryDtgoTu7ABM7JcOnz
- Manipulating response in onResponse hook HOT 1
- Bump fastify-reply-from dependency to fix critical severity vulnerability HOT 1
- is it stable enough to be used in production? HOT 1
- Error on fastify 4.13.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastify-gateway.