Skip to content

Commit

Permalink
Make reproxy workable on Bun and Cloudfalre Workers (#67)
Browse files Browse the repository at this point in the history
Run `Deno.serve()` when running on Deno and export `app` by default.
  • Loading branch information
5ouma authored Sep 29, 2024
1 parent 7a03f84 commit 751a600
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
48 changes: 44 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,30 @@ To do this, simply add the ref name to the sub-directory.

> [🌍 Environment Variables](#-environment-variables)
2. Run this command
2. Follow the steps depending on the runtime

```sh
deno run -A jsr:@5ouma/reproxy
```
- [🦕 Deno](https://deno.com)

1. Run this command

```sh
deno run -A jsr:@5ouma/reproxy
```

- [🍞 Bun](https://bun.sh)

1. Add this code to the `index.ts`

```ts
import "@5ouma/reproxy";
```

2. Run these commands

```sh
bunx jsr add @5ouma/reproxy
bun run index.ts
```

<br />

Expand All @@ -67,6 +86,27 @@ To do this, simply add the ref name to the sub-directory.
> [🌍 Environment Variables](#-environment-variables)
<br />
### ☁️ Use [Cloudflare Workers](https://workers.cloudflare.com)
1. Set up the `wrangler.toml`
> [🌍 Environment Variables](#-environment-variables)
2. Add this code to the `index.ts`
```ts
import "@5ouma/reproxy";
```
3. Deploy with these commands
```sh
npx jsr add @5ouma/reproxy
npx wrangler deploy index.ts
```
<br /><br />
## 🔨 Development
Expand Down
2 changes: 1 addition & 1 deletion src/server.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assertEquals } from "@std/assert";
import { STATUS_CODE } from "@std/http/status";

import { app } from "./server.ts";
import app from "./server.ts";
import {
exportRepo,
testRef,
Expand Down
5 changes: 3 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { checkRedirect, getContent, type Repository } from "./libs/mod.ts";
* });
* ```
*/
export const app: Hono = new Hono();
const app: Hono = new Hono();
export default app;
app.use(logger());
app
.get("/:ref?", async (ctx: Context) => {
Expand Down Expand Up @@ -55,4 +56,4 @@ app
return ctx.redirect("/", STATUS_CODE.SeeOther);
});

Deno.serve(app.fetch);
if (typeof Deno !== "undefined") Deno.serve(app.fetch);

0 comments on commit 751a600

Please sign in to comment.