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

fix: plugin routes support RouteConfig #2297

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/server/fs_extract.ts
Expand Up @@ -560,6 +560,7 @@ function getRoutesFromPlugins(plugins: Plugin[]): [string, RouteModule][] {
// deno-lint-ignore no-explicit-any
default: route.component as any,
handler: route.handler,
config: route.config,
}];
});
}
2 changes: 2 additions & 0 deletions src/server/types.ts
Expand Up @@ -580,6 +580,8 @@ export interface PluginRoute {

// deno-lint-ignore no-explicit-any
handler?: Handler<any, any> | Handlers<any, any>;

config?: RouteConfig;
}

export interface PluginIslands {
Expand Down
9 changes: 9 additions & 0 deletions tests/fixture_plugin/utils/route-plugin.ts
Expand Up @@ -4,6 +4,7 @@ import { AppBuilder } from "./sample_routes/AppBuilder.tsx";
import IslandPluginComponent from "./sample_routes/PluginRouteWithIsland.tsx";
import { SimpleRoute } from "./sample_routes/simple-route.tsx";
import AsyncRoute from "./sample_routes/async-route.tsx";
import RouteWithConfig from "./sample_routes/routeWithConfig.tsx";
export type { Options };

interface Options {
Expand Down Expand Up @@ -57,6 +58,14 @@ export default function routePlugin(
path: "pluginroutewithisland",
component: IslandPluginComponent,
},
{
path: "routeWithConfig",
component: RouteWithConfig,
config: {
skipAppWrapper: true,
skipInheritedLayouts: true,
},
},
],
islands: {
baseLocation: import.meta.url,
Expand Down
5 changes: 5 additions & 0 deletions tests/fixture_plugin/utils/sample_routes/routeWithConfig.tsx
@@ -0,0 +1,5 @@
import { defineRoute } from "$fresh/server.ts";

export default defineRoute((req, ctx) => {
return "This is a basic route.";
});
12 changes: 12 additions & 0 deletions tests/plugin_test.ts
Expand Up @@ -283,3 +283,15 @@ Deno.test("supports returning htmlText", async () => {
{ loadConfig: true },
);
});

Deno.test("plugin route supports config", async () => {
await withFakeServe(
"./tests/fixture_plugin/dev.ts",
async (server) => {
const res = await server.get("/routeWithConfig");
const body = await res.text();
assertStringIncludes(body, "<body>This is a basic route.</body>");
},
{ loadConfig: true },
);
});