I've been trying to use the swtoolbox for service worker. There is the case i want to use the url pattern matching to make network only and cache only.
i'm still stuck to make it work.
Basic usage is working fine.
toolbox.router.get('/index.html', () => new Response('Test'));
When i started using the Regex. It's not working as expected.
toolbox.router.get('/.*(\.html$)/', () => new Response('Test'));
It would be nice if anyone tried doing that make it work. I had use to validate my Regex is working fine first there. https://regex101.com/
found out that it assume as the string. I've to remove the single quote to run as the Regex.
toolbox.router.get(/.*(\.html$)/, () => new Response('Test'));
Related
I'm making my first coding project right now, a Discord BOT with discord.js. My main problem right now is setting multiple capitalization options for my prefix. The method i'm using right now for it is just "prefix": "f.", like all the other things in my options.json file. I would also like it to be "F." for mobile users, but using the same variable prefix. any way how? I've only found how to set the same value to multiple variables, but my issue is the exact opposite :/
Simply make the message content and prefix lower case before comparing them. For example:
const prefix = "f.";
client.on("message", (msg) => {
if (message.content.toLowerCase().startsWith(prefix.toLowerCase()) {
// starts with the prefix
}
});
I looked at the following posts but they did not help with this. It's probably simple, alas...
Express routes parameter conditions
https://forbeslindesay.github.io/express-route-tester/
I have the following regex - /^\d+x\d+/i. I want a number separated by an x, so a route would be /100x100,
The regex works on it's own, but not as a route. I tried various escapeings but I keep getting a 404 back. What would be the correct syntax? (I tried something like this already router.get('/\/^\d+x\d+/i'))
PS - As my plan is only to accept digit x digit, I'd be happy to hear about any flaws in this regex.
That's an interesting problem. This is one solution to achieve what you are looking for.
router.get('^/:dimensions([0-9]+[x][0-9]+)', function(req, res) {
//to show you that it hits the route and what it catches
res.send('Route match for dimensions: ' + req.params.dimensions);
});
This route need a little extra work in order for it to work properly, but I am not able to see what I need to do:
'http://<caregiverName:\w+>.' . $domain . '/<controller:\w+>/<action:\w+>' => '<controller>/<action>',
When I make call like this controller/action, everything works fine. When I make this call controller (without the explicit index) in order to make call to actionIndex, I am not able to catch caregiverName param. But when I make this call controller/index (index explicitly specified), it works normally.
What I need to rework in the router?
Two things:
Rule for calls without index
You need a second rule with the index as a static value when it is not provided. Add this after your first rule like so:
'http://<caregiverName:[\w-.]+>.' . $domain . '/<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'http://<caregiverName:[\w-.]+>.' . $domain . '/<controller:\w+>' => '<controller>/index',
The reason for this is that yii will to this normally, but not for your explicitly defined rule. The reason to put it after is that it would otherwise match before the other and always put you on the index page ;-).
Regex corrections for domain-characters
In you rule you use \w+ as a placeholder for a domain name. the way you specified your rule, it won't work with any other characters than "word-characters" (a-zA-Z0-9_). The dot (subdomain) and the dash (-) are missing! For the domain perfectly.valid-subdomain.com your rule won't work. You can find an axplanation of the regex shorthands here.
Check out my example above how I specified the character classes. You could of course also validate the length etc, but this is not the scope of this answer...you should get the gist.
Tell me if you need more information!
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');
I'm sure this is dead simple, which is why I'm so annoyed...
The problem originated from using translate_routes. This is very simple to use and presents no problem whatsoever. All I want is to be able to have the default locale prefix in the url, optionally.
Right now, I can do:
GET /controller/ and
GET /fr/controlleur/, but trying
GET /en/controller/ fails.
I figured that the en in the last example is not useful, so I want to 'remove' it using redirection. However, all my attempts up till now have failed.
How can I remove that prefix?
match "/en/*path" => redirect("/%{path}")
http://guides.rubyonrails.org/routing.html#redirection
http://guides.rubyonrails.org/routing.html#route-globbing