Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
epangelias opened this issue Dec 17, 2024 · 0 comments
Open

Comments

@epangelias
Copy link
Contributor

epangelias commented Dec 17, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant