question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Example of best practice (Async) Routes in a separate file

See original GitHub issue

Is 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:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
calumkcommented, Dec 14, 2020

@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

1reaction
talentlessguycommented, Dec 14, 2020

Fixed in v1.0.13:

pnpm i @tinyhttp/app@1.0.13
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found