What I am trying to accomplish is the following
$collection = new Phalcon\Mvc\Micro();
$collection->setHandler(new \app\Controllers\Brands());
$collection->setPrefix('api/brands');
$collection->get('','actionIndex');
$collection->post('/search','actionSearch');
$collection->get('/{id:[0-9]+}','resourceGet');
$collection->put('/{id:[0-9]+}','resourcePut');
$collection->delete('/{id:[0-9]+}','resourceDelete');
$app->mount($collection);
However no route is matched when going through it's URI as www.domain.com/api/brands/search, but the odd thing here is that the app itself can handle the routes if specified on the script as
$app->handle('api/brands/search');
A quick and dirty fix for this would be the following
$app->handle(substr($_GET['_url'], 1));
but I would like to know if there's a better way to solve it.
Any suggestion or answer is highly appreciated!
Thank you!
Make sure you set the base uri and make sure your routes start with '/'. That's the most common problem. Since you are using micro, I guess you don't need to worry about setBaseUri() because it's not used in your app.
$di->set('url', function(){
$url = new Phalcon\Mvc\Url();
$url->setBaseUri('/');
return $url;
});
$collection->setPrefix('/api/brands');
Related
I´m trying to use a different set of routes for each vhost
module.exports = function(app) {
app.use(vhost('www.example.com', exampleRoutes))
app.use(vhost('*.example.com', subdomainRoutes))
}
My problem is that www.example is also using the routes from subdomainRoutes
I need to somehow specify that if I´m under www then only the exampleRoutes should work
update. looks like I can use a regexp. I will need something like
not(www.example.com) but I´m terrible with regexp :(
laving this here in case someone needs it.
const regex = new RegExp('^(?!.*www.example.*).*$');
app.use(vhost(regex, subdomainRoutes))
I am using laravel for my backend api.
My question is about an scopefilter, the problem is that it is not responding when I call to it.
I have a lot of examples for using scopefilters.
So I looked at each of them to see if I did something wrong.
But I can't seem to find the problem.
When I call to this model in laravel, I use a parameter to define too the scopefilter to use a specific function.
The point only is that it never gets to this function, I don't get a response when I have put a log in this function.
I assume it is a syntax problem but maybe someone else can find the problem for this.
public static $scopeFilters = [
"supplierArticleClientId" => "bySupplierArticleClientId"
];
public function scopeBySupplierArticleClientId($query, $clientId) {
\Log::info([$clientId]);
}
In this case I expect that I see an clientId in my log.
You have to create a Custom validation function Implementing Rule Class
please go through this link for reference
I want to access context variable to use the isMobile flag to select a different endpoint depending on the result. I could pass it on the dispatch from the component, but I know there should be one way to do it.
export const actions = {
...
signUpGoogle({ commit }) {
fireauth.useDeviceLanguage()
if (context.isMobile) {
fireauth.signInWithPopup(GoogleProvider).then ...
} else {
fireauth.signInWithRedirect(GoogleProvider)
}
}
I saw here that it can be obtained on server init, but I really don't want to rely on this as caching will mess things up
https://nuxtjs.org/guide/vuex-store/#the-nuxtserverinit-action
Thanks for the help
I'm not sure if you're talking about an environment variable here, but below is the answer if it is.
Looking on this GH issue, we can find out that you can use this.app.$config.isMobile (basically referencing env variables aka publicRuntimeConfig values in your nuxt.config.js).
You can do one thing in nuxtServerInit, set this variable in state using the context, and then use state.isMobile to do this type of API Calls. Hopefully, that should solve this.
If it's not very clear, I can edit to give some code examples
I cannot use route parameters with app.use on Express 4.16.2.
I have a statement like this:
app.use('/course-sessions/:courseSessionId/chapter-sessions', chapterSessionsRouter)
And, in chapter sessions router:
// Index.
router.get('/', ...resource.indexMethods)
When I got '/course-sessions/0/chapter-sessions/', I have 404.
Then I am trying a statement like this:
app.get('/course-sessions/:courseSessionId/chapter-sessions', ...chapterSessionResource.indexMethods)
Now I have the result I want. So route parameters don't work with app.use.
While I am researching, I got this GitHub issue and this pull request which closes the issue. But it seems that the issue is still around here. Or do I make something wrong?
You have to setup your router in a different way, try using mergeParams to access parameters in parent routes.
let router = express.Router({ mergeParams: true });
See docs: http://expressjs.com/en/api.html
I’d do only app.use('/course-sessions/', chapterSessionsRouter) and handle the id inside the router.
I have a list of items along with a filter. I'd like to store the filter options in the window.location.hash property, so that I have nice sharable urls.
I am struggling to build a hash fragment which will work, using URI.js.
Vue.js 2.4.4
URI.js 1.19.0
What I've done so far
import Uri from "urijs";
let UriFragment = require('../../node_modules/urijs/src/URI.fragmentURI.js');
// UpdateHash method
let uri = new Uri(window.location.href);
uri.fragment({
providers: ['best', 'bestest'],
sort: 'recommended'
});
window.location.hash = uri.fragment();
What's happening?
example.com/list-of-things#![object Object]
What I expected to happen
As per the docs about 'fiddling with the fragment' http://medialize.github.io/URI.js/
example.com/list-of-things#providers=best&providers=bestest&sort=recommended
Question
How can I ensure that the plugin for URI.js is loaded and working? Then move onto figuring out why it's not outputting a formatted uri fragment.
I knew as soon as I posted, I would find the answer.
I was trying to use code for URI.fragmentURI.js when in fact I wanted URI.fragmentQuery.js.
Swapping to the correct plugin for the library has solved this problem.