Comments (7)
In summary, @tinyhttp/router
is more like an internal package. You should use subapps. For example
import { App } from "@tinyhttp/app"
const subApp = new App()
const app = new App()
subApp.post("/auth", handler)
app.use(subApp)
from tinyhttp.
Hi there. Thanks for posting the issue. Could you please post the import and subsequent use of authRoutes
?
from tinyhttp.
The authRoutes
is literally the imported router file which I described its contents, so I import it like usual, import router as authRoutes from "./authRoutes.js"
from tinyhttp.
The
authRoutes
is literally the imported router file which I described its contents, so I import it like usual,import router as authRoutes from "./authRoutes.js"
@talentlessguy, replied to a similar issue. See #400 (comment)
from tinyhttp.
Thanks so much @aarontravass! I see.
Was it designed to be that way? What would be the advantages of using this style of "subapps" over creating Router objects and integrating(.use) them in the main app, like I did?
Also, what is the point of @tinyhttp/router
then? What would be the use case for this feature?
Adding a few more context to this internal package on its README page would probably help others in the future who would end up in the same situation as me or this person who you mentioned.
from tinyhttp.
Was it designed to be that way?
Yes, I believe so.
What would be the advantages of using this style of "subapps" over creating Router objects and integrating(.use) them in the main app, like I did?
The router is just a bare-bones module and by itself has little to no use. Subapps are regular apps which can be nested and hence you have full control of each nested app which makes them way more powerful. This control is in the form of options/settings. The following are the ones you can set
tinyhttp/packages/app/src/app.ts
Lines 35 to 42 in bec8ee5
In contrast, the router gives no such flexibility.
Also, what is the point of @tinyhttp/router then?
The router just holds the middleware. Each handler or subapp you pass becomes the middleware for the main app/sub app and this is held in the router.
What would be the use case for this feature?
I am not sure about this.
Adding a few more context to this internal package on its README page would probably help others in the future who would end up in the same situation as me or this person who you mentioned.
Yes, I think this would be a good idea.
Hope this helps.
from tinyhttp.
As was mentioned before, @tinyhttp/router
is an internal package. I'm sorry for confusion, I'll add a "this is an internal package and is not meant to be used directly" to README.
Router's purpose is to move off middleware management to a separate utility class, router. You can't use it together with App unless you do some customization on top of it.
from tinyhttp.
Related Issues (20)
- res.sendFile should respect content type when set HOT 3
- Add .nvmrc to project root HOT 1
- Response object interface doesn't match @types/express behavior, it's not really generic HOT 6
- Simple Pull Request - License-none
- Failed to start https server HOT 1
- Multiple path arguments (as array) to route HOT 4
- Link CONTRIBUTING.md in README.md and mention forking as the first step instead of clone HOT 1
- Incompatible with Express middleware: `express.Handler` HOT 26
- Mounting a subapp on array of paths
- Add missing `accepts` TypeScript signatures HOT 4
- Mallformed URI's leads to crash with `/thing/:id` routes HOT 1
- app.use(<path>, <Router>) is Incompatible with Express HOT 8
- Create a community server HOT 8
- The website is down HOT 7
- Request `.xhr` misses fetch requests (headers are lowercase) HOT 3
- req.route always returns undefined HOT 19
- Server instance (of `@tinyhttp/app`) hangs on test since 2.0.33 HOT 4
- Predefined error type HOT 4
- ZOD support / example HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinyhttp.