Skip to content

Instantly share code, notes, and snippets.

@rzvdaniel
Created July 6, 2019 17:48
Show Gist options
  • Save rzvdaniel/559ae188763cf1024f051b9b178a4c06 to your computer and use it in GitHub Desktop.
Save rzvdaniel/559ae188763cf1024f051b9b178a4c06 to your computer and use it in GitHub Desktop.
[Medium] Moleculer Routing - RESTful Aliases
const ApiGateway = require("moleculer-web");
module.exports = {
name: "api",
mixins: [ApiGateway],
settings: {
port: process.env.PORT || 3000,
routes: [{
path: "/rest",
// RESTful aliases
aliases: {
"GET articles": "articles.list",
"GET articles/:id": "articles.get",
"POST articles": "articles.create",
"PUT articles/:id": "articles.update",
"DELETE articles/:id": "articles.remove"
},
// Disable direct URLs (`/articles/list` or `/articles.list`)
mappingPolicy: "restrict",
whitelist: [
// Access any actions in 'articles' service
"articles.*"
]
}]
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment