Skip to content

Proposal to change loading of routes, island, and static files in 2.0 #2793

Open
@epangelias

Description

@epangelias

I have found the new implementation for loading fresh islands, routes, and static files in Fresh 2.0 to have significant limitations.

  • It is not possible to create middleware for static assets #2759
  • It is not possible to add pages that inherit the app wrappers. As a result, it is difficult to create a plugin that adds pages, such as a user authentication plugin that includes a login page and inherits the page header. This makes it hard to separate features from a core app.
  • Adding a route with JSX or an island is very difficult unless created with fsRoutes.
app.use(staticFiles());

await fsRoutes(app, {
  dir: './',
  loadIsland: (path) => import(`./islands/${path}`),
  loadRoute: (path) => import(`./routes/${path}`),
});

I propose something like the following:

const router = new FSRouter(app);

accountPlugin(router);

router.loadIslandsDir('./islands/', import.meta.main)
    .loadRoutesDir('./routes/', import.meta.main)
    .loadStaticFiles('./static/', import.meta.main);

app.use(router.getMiddleware());

The developer can also prioritize the routes based on the order in which they add them.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions