Is there a way to add parameters on a moleculer-web route path?
I would like to add a parameter in the path to avoid to add in each alias.
I have tried to add a parameter, but after that, I could not reach the endpoint anymore
broker.createService({
mixins: [ApiService],
settings: {
routes: [
{
path: "/lng/:lng",
aliases: {
"GET /secret": [
auth.isAuthenticated(),
auth.hasRole("admin"),
"top.secret"
]
}
}
]
}
});
Thanks
No, you can use params in aliases only:
broker.createService({
mixins: [ApiService],
settings: {
routes: [{
path: "/lng",
aliases: {
"GET /:lng/secret": [
auth.isAuthenticated(),
auth.hasRole("admin"),
"top.secret"
]
}
}]
}
});
Related
I'd like to make my Vue 3 app, using Vue Router 4, to follow a pattern with nested children. This is my list of routes:
export default VueRouter.createRouter({
history: VueRouter.createWebHashHistory(),
routes: [
{
name: 'booking-start',
path: '/',
component: BookingStep1Component,
children: [
{
name: 'booking-step-1',
path: '/:from_gid/:to_gid',
component: BookingStep1Component,
children: [
{
name: 'booking-step-2',
path: ':date_from/:date_to',
component: BookingStep2Component,
children: [
{
name: 'booking-step-3',
path: ':time_from/:time_to',
component: BookingStep3Component
},
]
}
]
}
]
}
]
})
So if I go the the url /# I would like to get the BookingStep1Component displayed, same goes with /#123/456. If I go to /#123/456/2022-01-01/2022-02-28, I'd like to see BookingStep2Component, and if I go to /#123/456/2022-01-01/2022-02-28/10:00/13:00, I'd like to see BookingStep3Component. But things get mixed up somewhere and I do not see the right component at some stage.
Is there anything obvious I am missing here?
Not sure, but I do not use a "/" at the beginning of childs like at booking-step-1.
Although I have not used paths, beginning with a param ... should work, but I would try it out.
I use Nuxt.js with nuxt-i18n in "strategy: 'prefix'" mode. About this strategy.
And I have a problem:
when I try get the homepage of application, Nuxt redirect me to localhost:3000/en/, but I need redirect to localhost:3000/en. Without this pernicious trailing slash on the end!
There is snippet of my nuxt.config.js file:
modules: [
['nuxt-i18n',
{
locales: ['en', 'es'],
defaultLocale: 'en',
strategy: 'prefix',
vueI18n: {
fallbackLocale: 'en',
messages: {
en: {
greeting: 'Hello world!'
},
en: {
greeting: '¡Hola mundo!'
}
}
}
}]
]
Any ideas?
I have used #nuxtjs/redirect-module, and set redirect options { from: '/en/', to:'/en' }. It works.
I have a website built around angular 2 running on Apache. The same website (and same API) is used by different "groups". Let's say there are two groups: bees and wasps. My angular routing file looks like this:
{
path: '',
redirectTo: 'groupe/1',
pathMatch: 'full'
},
{
path: 'groupe',
children: [
{
path: ':groupe',
children: [
{
path: '',
component: HomePage,
},
...
To access a group, I can then simply go to http://myws.com/group/1 (for bees) and http://myws.com/group/2 (for wasps). Pages are then basically the same for each group (with different content, loaded from an API), like: http://myws.com/group/1/page/21.
Now the tricky part. First I want to access each "group" from a simplified, explicit URL: like http://myws.com/bees. I can do this by adding the following code to the router :
{
path: 'bees',
redirectTo: 'groupe/1',
pathMatch: 'prefix'
},
Problem is, the route changes in the URL back to /group/1. Is there a way to make the /bees permanent, hiding /group/1 ?
Now, I also want to access my bees group from a specific domain, like http://www.bees.com. Pages should render like http://www.bees.com/page/21 Is there a way with angular or Apache to do this?
Well, on the Angular side (meaning everything after the .com), you can do like so
export const bugRoutes: Routes = [
{ path: 'bees', canActivate: [MyBeeGuard], children: [
{ path: '', component: BeeHomeComponent },
{ path: '**', component: BeeHomeComponent }
]},
{ path: 'wasps', canActivate: [MyWaspGuard], children: [
{ path: '', component: WaspHomeComponent},
{ path: '**', component: WaspHomeComponent}
]},
{ path: '**', component: ChoseBugHomeComponent }
];
This way, your user will be redirected to any bug home, no matter the route. And if he inputs no route at all, he will be redirected to a component that "allows" him to chose which bug to chose
I'm using good plugin for my app, and I have copied the config parameters straight from the sample in the page, console and file are working , but good-http is not working!
here is my configuration:
myHTTPReporter: [
{
module: 'good-squeeze',
name: 'Squeeze',
args: [{error: '*', log: 'error', request: 'error'}]
},
{
module: 'good-http',
args: [
'http://localhost/log-request/index.php?test=23424', // <- test file I created to see if data is being sent or not
{
wreck: {
headers: {'x-api-key': 12345}
}
}
]
}
]
the only argument that is actually working is the ops: * and none of the error: *, ... is working
Am I missing something in my config parameters?
Maybe you should change the threshold parameter of the plugin, is set by default to 20 so it only send data after 20 events. If you want immediate results yo have to change it to 0.
myHTTPReporter: [
{
module: 'good-squeeze',
name: 'Squeeze',
args: [{error: '*', log: 'error', request: 'error'}]
},
{
module: 'good-http',
args: [
'http://localhost/log-request/index.php?test=23424', // <- test file I created to see if data is being sent or not
{
threshold: 0,
wreck: {
headers: {'x-api-key': 12345}
}
}
]
}
]
How do we get around the "document is not defined" error when doing a r.js build via r.js -o against a dijit?
Specifically, I'm trying to build r-build.js:
define(["require", "exports", "dijit/layout/ContentPane"], function (require, exports, ContentPane) {
function simple() {
return ContentPane;
}
return simple;
});
Using r.js.cmd -o r-build.js and it reports:
ReferenceError: document is not defined
In module tree:
test/simple
dijit/layout/ContentPane
dijit/_Widget
dojo/query
dojo/selector/_loader
My r-build.js file looks like this:
({
appDir: "../",
baseUrl: "amd",
dir: "../../release",
optimize: "none",
modules: [
{
name: "test/simple",
exclude: ["jquery", "dojo"]
}
],
packages: [
{
name: 'cm',
location: 'http://localhost:93/CodeMirror'
},
{
name: 'jquery',
location: 'd:/code/jquery/src',
main: 'jquery'
},
{
name: 'jquery/ui',
location: 'http://localhost:93/jquery-ui/ui'
},
{
name: 'jquery/themes',
location: 'http://localhost:93/jquery-ui/themes'
},
{
name: 'sizzle',
location: 'http://localhost:93/jquery/external/sizzle/dist',
main: 'sizzle'
},
{
name: 'dojo',
location: 'd:/code/dojo'
},
{
name: 'dijit',
location: 'd:/code/dijit'
},
{
name: 'xstyle',
location: 'http://localhost:93/xstyle'
}
]
})
I'm fighting with the same issue. Building a r.js bundle with Dojo is a pain.
That one can be easy to fix... If you don't have problems with the supported browsers (post pre-ie9, for instance) override that file and change the lines that check the querySelectorAll to true and you will not need to do those checks. Like...
has.add("dom-qsa2.1", true);
has.add("dom-qsa3", true);
Hope it helps a bit...