Skip to content

Commit c4aa9e8

Browse files
committed
fix: strip extension from partial routes
1 parent 6e9c811 commit c4aa9e8

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

builder.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,12 @@ export type BuildConfig = {
305305
readonly builders: readonly Builder[];
306306
};
307307

308+
function strip_extension(path: string): string {
309+
const parsed_path = Path.parse(Path.normalize(path));
310+
const stripped = Path.join(parsed_path.dir, parsed_path.name);
311+
return stripped;
312+
}
313+
308314
/**
309315
* Converts a PartialRoute token to a full Route with file path information.
310316
*
@@ -327,7 +333,7 @@ export function from_partial_route(
327333
return full_route(
328334
builder,
329335
file_entry.parsed_path,
330-
Router.route(method, file_entry.relative_path, handler),
336+
Router.route(method, strip_extension(file_entry.relative_path), handler),
331337
);
332338
}
333339

builder_server.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as Option from "@baetheus/fun/option";
22
import * as Array from "@baetheus/fun/array";
33
import * as Effect from "@baetheus/fun/effect";
4+
import * as Path from "@std/path";
45
import { pipe } from "@baetheus/fun/fn";
56

67
import type * as Router from "./router.ts";
@@ -31,6 +32,12 @@ export type ServerBuilderOptions = {
3132

3233
const filterPartialRoute = Option.fromPredicate(Tokens.is_partial_route);
3334

35+
function strip_extension(path: string): string {
36+
const parsed_path = Path.parse(Path.normalize(path));
37+
const stripped = Path.join(parsed_path.dir, parsed_path.name);
38+
return stripped;
39+
}
40+
3441
function wrap_handler(
3542
handler: Router.Handler,
3643
middlewares: readonly Router.Middleware<unknown>[],

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@baetheus/pick",
3-
"version": "0.14.0",
3+
"version": "0.15.0",
44
"unstable": [
55
"bundle"
66
],

0 commit comments

Comments
 (0)