Code Monkey home page Code Monkey logo

Comments (7)

aarontravass avatar aarontravass commented on June 6, 2024 1

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.

aarontravass avatar aarontravass commented on June 6, 2024

Hi there. Thanks for posting the issue. Could you please post the import and subsequent use of authRoutes?

from tinyhttp.

phtdacosta avatar phtdacosta commented on June 6, 2024

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.

aarontravass avatar aarontravass commented on June 6, 2024

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.

phtdacosta avatar phtdacosta commented on June 6, 2024

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.

aarontravass avatar aarontravass commented on June 6, 2024

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

export type AppSettings = Partial<{
networkExtensions: boolean
subdomainOffset: number
bindAppToReqRes: boolean
xPoweredBy: string | boolean
enableReqRoute: boolean
views: string
}>

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.

talentlessguy avatar talentlessguy commented on June 6, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.