Using wildcards when mapping routes with MapWebPageRoute - razor

In an ASP.NET Web Pages project (not Web Forms, not MVC) I am using Mike Brind's
More Flexible Routing For ASP.NET Web Pages.
I want to create a route that picks ups any number of route elements but ending in a specific word, eg:
mydomain.com/route1/word
mydomain.com/route1/route2/word
mydomain.com/route1/route2/route3/word
...etc etc
I tried to use wildcards when mapping the route but that didn't work, eg:
RouteTable.Routes.Ignore("{*routes}/word");
Is there a way to map these route possibilites or do I have to create a route for each possibiility, eg:
RouteTable.Routes.MapWebPageRoute("{route1}/word", "~/mypage.cshtml");
RouteTable.Routes.MapWebPageRoute("{route1}/{route2}/word", "~/mypage.cshtml");
RouteTable.Routes.MapWebPageRoute("{route1}/{route2}/{route3}/word", "~/mypage.cshtml");
...etc etc

I eventually figured out a solution to this.
RouteTable.Routes.MapWebPageRoute("{*routes}",
"~/mypage.cshtml",
constraints: new { routes = #".*(/word)" });
So using constraints was the answer.

Related

User-created routes ExpressJS

there are websites which create custom sessions for users, giving them unique link to the exact session user has created. E.g. it would like something like https/website.com/session/UniqueRandomID. I guess I understand how custom routes in ExpressJS work, but I'm not quite sure how can I allow a user to create those and later allow other users to connect only to those which have been already created..
Is there a common way of doing it and what may I be missing on the topic?
I tried searching the expressJS documentation.
The term "session" has a rather specific meaning in web site development (it refers to data associated with a given browser's visit to a site and is used for things like tracking the logged in state of a user) so I'll use the term "project" in this answer.
When the user creates a project, store all the information about that project in a database. Include, as part of this information an identifier. You probably want this to be a GUID or similar (there are libraries which will generates these for you) rather than something sequential (like an automatically generated database primary key).
The first page of the React Guide explains routing. Create a route that uses a route parameter for the project ID.
Use that project ID to get the data about the project from your database.
If there isn't any for that ID, return an error.
app.get('/projects/:projectId', async (req, res) => {
const projectData = await getProjectData(req.params.projectId);
if (projectData) {
return res.render('projectView', projectData);
}
res.sendStatus(404);
})

How can I get window.location.href in VuePress V2

I'm trying to display a dynamic link to a Quiz from inside my VuePress V2 documentation. Since that game will be hosted on several IP's, i need to dynamically generate that URL.
Game and documentation will always run on the same IP, but different port.
I am looking for something like this in my markup file:
# Quiz
[Click here to start the quiz](<script>document.write(window.location.href.replace('3000','8080')</script>)
I know I can't use script, but i am hoping for one of the following:
Like i can keep the protocol by calling //example.com and keeping the URL by calling /subfolder, maybe there is a way to call :8080// or sth...
I can make use of the fact that Vue Syntax is allowed. There is a way I can implement logic into .md files by writing
I have { 1+1 } hands.
That will convert to
I have 2 hands.
I can write a custom Vue component and in there reference window.location.href.

How do you cache a route with a wildcard in a PWA service worker?

I'm trying to convert my application to a PWA and I understand that I need to provide a complete list of endpoints and static files to the service worker, so it can manage the caching. In all the examples I'm finding, the pages are static links like /report. But in most real world applications, the pages contain dynamic parts, like /report/{reportId:int}. How do you tell the service worker about such an endpoint?
You can use javascript test() method and check if the url matches the regExp expression that would fit your url.
You can read about it on this official guide:
https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook#putting_it_together
extract:
if (/^\/article\//.test(requestURL.pathname)) {
event.respondWith(/* some other combination of patterns */);
return;
}

Dynamic Subdomain Routing With NextJS

How can the Dynamic Sub domain routing feature be implementing in NextJS?
Example: If a user comes with username abc in site xyz then he can access his
site on abc.xyz.com
Also, if the user have abc.com domain then he can point abc.com to abc.xyz.com
So in future if someone opens abc.com then abc.xyz.com is served. And in URL
also the abc.com is shown.
I have investigated few plugin in NPM like vhost and wildcard-subdomains but not sure that is right way to take on this issue.
The vhost requires changes in system hosts in local system and wildcard-subdomain solves the issue purely with routing.
The Local System Setting I have customized Server.js With Code Which Works Temporarily, but does't seems to be a solution which can be used in production :
Server.js
...
if (pathname === "/demo.demo.com") {
app.render(req, res, "/demo.demo.com", query);
}
...
And in _app.js
static async getInitialProps(appArgument) {
...
return {
...
renderFrom: "demo.demo.com"
};
}
Also in my host I have demo.demo.com point to localhost.
The site works for me in demo.demo.com:3000 but how to generalise it in production scenarios
with Database and CNAME Records and add/change CNAME Record automatically with User Action.
On Vercel (the creators of Next.js), we support Wildcard Domains out of the box. Within Next.js, you then only need to read the Domain from the headers of the incoming request, parse it and then respond with the right content.
I hope that was helpful!
I just found this blog post https://demo.vercel.pub/platforms-starter-kit, which was published 6 days ago.
It announces https://platformize.co/, a product that does just that.
Multi-tenant applications serve multiple customers across different subdomains/custom domains with a single unified codebase.
For example, this blog is a multi-tenant application:
Subdomain: demo.vercel.pub
Custom domain: platformize.co (maps to demo.vercel.pub)
Build your own: app.vercel.pub
Another example is Hashnode, a popular blogging platform. Each writer has their own unique .hashnode.dev subdomain for their blog:
eda.hashnode.dev
katycodesstuff.hashnode.dev
pit.hashnode.dev
Users can also map custom domains to their .hashnode.dev subdomain:
catalins.tech → pit.hashnode.dev

Symfony FosRestBundle - Hyphenated rest routes

I'm currently learning the basics of the FosRestBundle in a basic Symfony 3 project and am looking at creating a hyphenated REST route.
An example of a simple route I currently have, where GET /coffees hits CoffeeController::getCoffeesAction() as expected;
coffees:
type: rest
resource: ApiBundle\Controller\CoffeeController
I'm now looking at creating another rest controller to represent a coffee pot, so URLs follow a format like GET /coffee-pots to hit CoffeePotsController::getCoffeePotsAction(). I've tried every key I can think of whilst referencing the docs ("coffee-pots", coffeePots, coffee_pots etc) and I only ever get a 404. The rest of the configuration is correct, since if I change the key and action to just pots it works fine.
I have successfully implemented routing annotations within the Controller (e.g. #Get("/coffee-pots", name="get_coffee_pots")) but I'd rather avoid that unless it's a particularly bad practice to do so.
Is this possible? Thanks!
Old question but I just ran into this. From the console, type the following to list all of your routes:
php app/console debug:router
It will likely be at /coffeepots.