Example of best practice (Async) Routes in a separate file
See original GitHub issueIs your feature request related to a problem? Please describe. Could you please provide an Example of placing (Async) routes in a separate file
Describe the solution you’d like I am unable to successfully include a route with async functions in a separate file.
The following - Works perfectly in the main file.
app.get('/asyncTest', (req, res) => {
res.render('index.eta', {
name: 'Calum',
af : asyncFunctions
});
});
The following - fails if placed in a separate routes.js file. (route containing non-async works)
router.get('/asyncTest', (req, res) => {
res.render('index.eta', {
name: 'Calum',
af : asyncFunctions
});
});
attached with app.use(router)
,
Warning is Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
Additional context If there is any chance of adding an example showing how to do this, that would be appreciated 👍
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Camel - Best practice to start an asynchronous route from ...
In a Camel route I have to start (in async mode and request only) another route countinuing the processing in the main route....
Read more >Express Tutorial Part 4: Routes and controllers - MDN Web Docs
In this tutorial we'll set up routes (URL handling code) with "dummy" ... good understanding of how to create modular routes using Express!...
Read more >How To Handle Async Data Loading, Lazy Loading, and Code ...
In this tutorial, you'll handle asynchronous data in React by creating an ... Defensive programming is usually considered a best practice, ...
Read more >Express Explained with Examples - Installation, Routing ...
In this tutorial, we are going to look into Express which is a Node.js framework for web development that comes with features like...
Read more >The Art of Routing in Flask - Hackers and Slackers
Empower your Flask application to grow dynamically with intelligent routes and well-structured views.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@talentlessguy , Many thanks for your work on this, I really appreciate it, and how quick you were.
I can confirm - 1.0.13 fixed the issue without the need for me to re-write anything.
{async: true} is not required, due to new sugar in Eta -> Eta.renderFileAsync https://github.com/eta-dev/eta/issues/49
Fixed in v1.0.13: