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

feat: jsr support + deno serve support #13

Merged
merged 7 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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: canary
load1n9 marked this conversation as resolved.
Show resolved Hide resolved

- 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.
8 changes: 7 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{
"importMap": "./import_map.json"
"name": "@denosaurs/rutt",
"version": "0.1.0",
load1n9 marked this conversation as resolved.
Show resolved Hide resolved
"imports": {
"https://deno.land/x/rutt/mod.ts": "./mod.ts",
"jsr:@denosaurs/rutt": "./mod.ts"
},
load1n9 marked this conversation as resolved.
Show resolved Hide resolved
"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 "jsr:@denosaurs/rutt";

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 "jsr:@denosaurs/rutt";

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 "jsr:@denosaurs/rutt";

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 "jsr:@denosaurs/rutt";

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
9 changes: 3 additions & 6 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 { router } from "./mod.ts";
import { assert, assertEquals, assertIsError } from "jsr:@std/[email protected]";
import { router } from "jsr:@denosaurs/rutt";
load1n9 marked this conversation as resolved.
Show resolved Hide resolved

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