I have a meteor application and am using Iron Router for the routing.
I've got one route called /process which is run server side. In the URL parameters i have a parameter named route. What i want to do is for the handler for the route handler to return the HTML that was generated from the route specified in the parameter using this.res.end(- the rendered HTML from the route parameter's route-)
This is bound to be possible but my meteor skills are lacking.
Related
I wish to call an API on the path/route change of a react web app. How can I achieve this if I wish to call an API only once the route or the path changes.
Note that I have tried this in route file inside an useEffect by giving dependency of the route but it is executing for all the routes at once, eg. 50 routes, 50 API calls which is expected.
Is there anything with which help I can achieve this?
So I have a routes.js file to handle my routing in my VUE app and I have used it to transition between components successfully using a router-link tag. However I would now like to execute routes using javascript. For example after I receive an authentication response from my server I would like to transition from the login page to my home page. What can I do to execute a route when I want to?
You can programmatically route using router.push('home'). Here is a a reference to see more options available.
I've set up a meteor app using iron-router and I want the app to listen to a webhook from another service (basically I'm building an API for other services to use)
So for example, when an external website calls myapp.meteor.com/webhook I want to catch that specific link and parameters and do stuff with the data.
Update: Thanks to a comment I found this: https://github.com/iron-meteor/iron-router/blob/devel/Guide.md#server-routing
Router.route('/webhooks', { where: 'server' })
.post(function () {
console.log(this);
this.response.end('Caught you\n');
//this.response.status(200).json({text:"Todo added"});
});
I added the above in the /server folder as there is no need to for the front-end server to worry about this like mentioned in the comment. But when I load this using postman POST request, it just returns my HTML for not found. Any ideas?
Thanks in advance for your help.
UPDATE
I tried what #David said and still I get the template loaded and nothing in the console. Any idea what I'm doing wrong?
Your server route will only run if no client routes also match. I suspect you have a catch-all route which is executing on the client and preventing the server route from running. One solution is to define all of the routes in a common folder like /lib so that you can properly order them. Your routes file could look something like:
client route 1
client route 2
server route 1
server route 2
catch-all (not found) route
I'm trying to use HTML5 push state links with my Angular app. What I have is a series of routes similar to the following
$stateProvider.state('product', {
url: '/product/:productCode',
templateUrl: 'product/product.html',
controller: 'ProductCtrl'
}
});
This works when I navigate to [host]/#/product/ABC123 - It displays the url in the browser as /product/ABC123, then when I start clicking through to my other routes (using ui-sref) everything works as expected.
However - I'd like the ability to both refresh the browser, and remain in the same state, as well as be able to copy and paste that link and route to the right state.
eg. If I got to [host]/product/ABC123 - I want to display the content from the #/product/ABC123 route. Currently, this will give me a not found.
I'm using nginx as my app server. I believe I'll have to add something to handle it at that level, but I'm not sure where to start.
The issue you have is that your server does not know how to respond to /product/ABC123.
I am currently using node.js for my backend with angular, and to solve this I return the angular app for all routes, not just the usual root route for example.
So you might have used something like this in the past:
app.get('/', ...);
Which would have returned the angular app just for the root route. Now I use something like:
app.get('*', ...);
Which will return the angular app for all routes.
I should have mentioned that this can act as a catch all placed after other routes such as for static files. Another alternative is to mark all the routes you want specifically for the angular app, eg:
app.get('/', ...); app.get('/product/:productId', ...); etc
This is probably a simply routing issue but after a quick google I haven't clicked as to what I am doing wrong with the routing.
When using SignalR the routing MapConnection corrupts the default MVC route renderings.
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new { favicon = #"(.*/)?favicon.ico(/.*)?" });
// default MVC
routes.MapRoute("Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
// SignalR routing
routes.MapConnection<EventConnection>("echo", "echo/{*operation}");
In this order I get a 404 when SignalR js client connects to /echo/ url.
If I swap the default MVC and SignalR routing around, the SignalR js client connects to /echo/ url and SignalR functions correctly but the Routes are rewritten incorrectly when rendered to the view i.e.
/echo?action=Index&controller=Home
Am I missing something obvious? I am looking at ExclusionConstraints to exclude the echo path but this seems heavy handed, surely there is a simplier way?
Also, I have tried using Regex contraint like in the following question which doesn't work.
MVC2 Routing with WCF ServiceRoute: Html.ActionLink rendering incorrect links!
I ended up fixing this in the SignalR code using the below answer and submitting a pull request.
Html.ActionLink construct wrong link when a non-mvc route is added
https://github.com/SignalR/SignalR/pull/19