Skip to content

Commit

Permalink
feat: jsr support + deno serve support (#13)
Browse files Browse the repository at this point in the history
Co-authored-by: Elias Sjögreen <[email protected]>
  • Loading branch information
load1n9 and eliassjogreen authored Sep 18, 2024
1 parent 1aeb488 commit e42dcf1
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 25 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish
on:
workflow_dispatch:
release:
types: [published]

jobs:
publish:
runs-on: ubuntu-latest

permissions:
contents: read
id-token: write

steps:
- uses: actions/checkout@v4
- name: Install Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: Publish package
run: deno publish
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022-2023 the denosaurs team
Copyright (c) 2022-2024 the denosaurs team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ the web-standard
provide fast and easy route matching.

```ts
import { router } from "https://deno.land/x/rutt/mod.ts";
import { router } from "jsr:@denosaurs/rutt";

await Deno.serve(
router({
Expand All @@ -16,6 +16,19 @@ await Deno.serve(
).finished;
```

## Usage with `deno serve`

```ts
import { router } from "jsr:@denosaurs/rutt";

export default {
fetch: router({
"/hello/:name": (_req, _, { name }) =>
new Response(`Hello ${name}`, { status: 200 }),
}),
};
```

## Projects using `rutt`

- [denoland/fresh](https://github.com/denoland/fresh)
Expand All @@ -33,4 +46,4 @@ Pull request, issues and feedback are very welcome. Code style is formatted with

### Licence

Copyright 2022-2023, the denosaurs team. All rights reserved. MIT license.
Copyright 2022-2024, the denosaurs team. All rights reserved. MIT license.
4 changes: 3 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"importMap": "./import_map.json"
"name": "@denosaurs/rutt",
"version": "0.3.0",
"exports": "./mod.ts"
}
2 changes: 1 addition & 1 deletion examples/hello_world.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { router } from "https://deno.land/x/rutt/mod.ts";
import { router } from "../mod.ts";

await Deno.serve(
router({
Expand Down
2 changes: 1 addition & 1 deletion examples/nested_routes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { router } from "https://deno.land/x/rutt/mod.ts";
import { router } from "../mod.ts";

await Deno.serve(
router({
Expand Down
2 changes: 1 addition & 1 deletion examples/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { router } from "https://deno.land/x/rutt/mod.ts";
import { router } from "../mod.ts";

await Deno.serve(
router({
Expand Down
8 changes: 8 additions & 0 deletions examples/serve.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { router } from "../mod.ts";

export default {
fetch: router({
"/hello/:name": (_req, _, { name }) =>
new Response(`Hello ${name}`, { status: 200 }),
}),
};
5 changes: 0 additions & 5 deletions import_map.json

This file was deleted.

16 changes: 8 additions & 8 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ export interface Routes<T = {}> {
* {@link MatchHandler} is called.
*/
// deno-lint-ignore ban-types
export type InternalRoute<T = {}> = {
export interface InternalRoute<T = {}> {
pattern: RegExp | URLPattern;
methods: Record<string, MatchHandler<T>>;
};
}

/**
* An array of {@link InternalRoute internal route} objects which the
Expand Down Expand Up @@ -293,13 +293,13 @@ export function router<T = unknown>(

if (methods["any"]) {
return await methods["any"](req, ctx, groups);
} else {
return await unknownMethodHandler!(
req,
ctx,
Object.keys(methods) as KnownMethod[],
);
}

return await unknownMethodHandler!(
req,
ctx,
Object.keys(methods) as KnownMethod[],
);
}
}

Expand Down
7 changes: 2 additions & 5 deletions test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {
assert,
assertEquals,
assertIsError,
} from "https://deno.land/[email protected]/assert/mod.ts";
import { assert, assertEquals, assertIsError } from "jsr:@std/assert@^1";
import { router } from "./mod.ts";

/// @ts-ignore - Deno doesn't have this type
const TEST_CONN_INFO: Deno.ServeHandlerInfo = {
remoteAddr: {
transport: "tcp",
Expand Down

0 comments on commit e42dcf1

Please sign in to comment.