8000 fix(app): enable router preemptive mode by pi0 Β· Pull Request #1504 Β· nitrojs/nitro Β· GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(app): enable router preemptive mode #1504

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

Merged
merged 2 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/runtime/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ function createNitroApp(): NitroApp {
},
});

const router = createRouter();
const router = createRouter({
preemptive: true,
});

h3App.use(createRouteRulesHandler());

Expand Down
3 changes: 3 additions & 0 deletions test/fixture/api/upload.post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default eventHandler((event) => {
return "uploaded!";
});
10 changes: 10 additions & 0 deletions test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ export function testNitro(
expect(paramsData2).toBe("foo/bar/baz");
});

it("Handle 404 not found", async () => {
const res = await callHandler({ url: "/api/not-found" });
expect(res.status).toBe(404);
});

it("Handle 405 method not allowed", async () => {
const res = await callHandler({ url: "/api/upload" });
expect(res.status).toBe(405);
});

it("handles route rules - redirects", async () => {
const base = await callHandler({ url: "/rules/redirect" });
expect(base.status).toBe(307);
Expand Down
0