Comments (4)
config:
// Export the schema of service
const ApiGwService = require("moleculer-web");
module.exports = {
mixins: [ApiGwService],
settings: {
port: 3000,
middleware: false,
routes: [{
// Path prefix to this route (full path: /api )
path: "/contentful",
// Whitelist of actions (array of string mask or regex)
whitelist: [
'*'
],
// Action aliases.
aliases: {
'POST /update': 'contentful.update',
},
// get headers
onBeforeCall(ctx, route, req, res) {
ctx.meta.headers = req.headers;
},
// Use bodyparser module.
bodyParsers: {
json:{ type: ['application/vnd.contentful.management.v1+json','application/json'] },
urlencoded: {
extended: true
}
}
}, {
// Path prefix to this route (full path: /api , / ...)
path: "/",
// Whitelist of actions (array of string mask or regex)
whitelist: [
'*'
],
// authorization.
authorization: true,
// Action aliases.
aliases: {
'GET :client/v1/:lang?/content': 'testa.content',
'GET :client/v1/labels': 'testa.roilabels',
'POST :client/v1/update': 'contentful.update',
'POST :client/v1/support': 'testa.sendgrid',
},
// Use bodyparser module.
bodyParsers: {
json:{ type: ['application/vnd.contentful.management.v1+json','application/json'] },
urlencoded: {
extended: true
}
}
}]
},
methods: {
authorize(ctx, req, res) {
ctx.meta.user = {
id: 1,
name: "John Doe",
};
return Promise.resolve(ctx);
}
}
}
actually no need for some special config!
we can add default example
and then try to access any routes - it will return 404 not found and explanation message:
https://fortum.frodbrow.com/parent/child/granchild
{
"name": "ServiceNotFoundError",
"message": "Service 'parent.child.granchild' is not available!",
"code": 404,
"type": null,
"data": {
"action": "parent.child.granchild"
}
}
https://fortum.frodbrow.com/parent/child/granchild/../../
{
"name": "ServiceNotFoundError",
"message": "Service 'parent' is not available!",
"code": 404,
"type": null,
"data": {
"action": "parent"
}
}
https://fortum.frodbrow.com/parent/child/../../granchild/../funny
{
"name": "ServiceNotFoundError",
"message": "Service 'funny' is not available!",
"code": 404,
"type": null,
"data": {
"action": "funny"
}
}
from moleculer-web.
Thanks, I will check it.
from moleculer-web.
What is the exact problem with it?
If you open the link in browser, the browser will solve the ..
in path and will open directly the ../parent/ address only (on browser side).
If you call it in for exampl Postman, the ..
won't be solved.
https://fortum.frodbrow.com/parent/child/granchild/../../
{
"name": "ServiceNotFoundError",
"message": "Service 'parent.child.granchild......' is not available!",
"code": 404,
"type": null,
"data": {
"action": "parent.child.granchild......"
}
}
I think it is not a Moleculer issue.
from moleculer-web.
My bad - did not look closer..
from moleculer-web.
Related Issues (20)
- Q&A: How can I remove the service name from the api endpoint? HOT 6
- Could not handle the request when the request come with files and data in multipart HOT 2
- Sometime the list of REST api is missing some functions HOT 1
- multipartHandler throws unhandled error if payload is too large
- CORS Preflight Issue HOT 2
- Response headers affectation HOT 2
- Missing interface when upload file. HOT 2
- resetTime should accept function
- Undefined `actions` property in `/api/~node/services?withActions=true` causes empty REST API page HOT 1
- Route-level `mergeParams` doesn't exist for auto aliases HOT 1
- Cannot skip route with middleware HOT 1
- Improve routes priorization HOT 1
- RateLimit didn't check if trusted proxy send the header x-forwarded-for HOT 4
- REST shortcut doesn't handle action object correctly
- Typescript error: import { IParseOptions } from 'qs'
- Can we get an official interface for ctx.meta.$ fields available in moleculer-web?
- Routes with autoAliases not considered for started HOT 1
- Allow define action type in auto aliases (rest action param) HOT 2
- What is the benefit of using ctx.meta.$location & ctx.meta.$responseType vs just setting via ctx.meta.$responseHeaders? HOT 4
- update request body value in onBeforeCall hook not working HOT 1
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 moleculer-web.