This module provides a very simple server for creating github mirroring sites with deno deploy.
This module is available in the code for deno deploy. However, it uses
Deno.listen (), so it also works with the deno CLI. I made this to increase
the options other than deno.land that can be used to publish the module.
Place serve.ts in your repository with the following:
// serve.ts
import { serve } from "https://deploy-gitrepo.deno.dev/v0.0.3/serve.ts";
serve({
owner: "your_account_name",
repo: "your_repository_name",
});Sign up for deno deploy, create a new project, and register serve.ts in "git integration".
- The URL looks like this:
https://<your_domain>/<version>/<path_to_file> - Great for delivering Deno modules.
- You can convert markdown to HTML and use it as an alternative to github pages.
- This website is hosted by deploy_gitrepo.
// serve.ts
import { serve } from "https://deploy-gitrepo.deno.dev/v0.0.3/serve.ts";
import { mdToHTML } from "https://deploy-gitrepo.deno.dev/v0.0.3/md_to_html.ts";
const converters = [{
// When `match` returns true, the` convert` function is called.
match: (request: Request) => new URL(request.url).pathname.endsWith(".md"),
convert: mdToHTML,
}];
serve({
owner: "your_account_name",
repo: "your_repository_name",
converters,
});- You can convert TypeScript to JavaScript and use it to deliver ES Modules.
- This example returns TypeScript when accessed from Deno and transpiled to JavaScript when accessed from a non-Deno (browser).
- Override the response headers by setting the
headersproperty in the return value of the convert function.
// serve.ts
import { serve } from "https://deploy-gitrepo.deno.dev/v0.0.3/serve.ts";
import { tsToJs } from "https://deploy-gitrepo.deno.dev/v0.0.3/ts_to_js.ts";
const converters = [{
// Only the first matching converter will be used.
match: (request: Request) =>
new URL(request.url).pathname.endsWith(".ts") &&
!request.headers.get("user-agent")?.includes("Deno"),
convert: tsToJs,
}, {
match: (request: Request) => {
const { pathname } = new URL(request.url);
return pathname.endsWith(".ts") || pathname.endsWith(".js");
},
convert: ({ content }: { content: string }) => ({
content,
headers: { "Access-Control-Allow-Origin": "*" },
}),
}];
serve({
owner: "your_account_name",
repo: "your_repository_name",
converters,
});Supports github personal access tokens.
- Internally this uses the github API to get the content.
- You can use it without a token, but you can use a token to increase the maximum number of requests.
- Set the token in an environment variable. In the argument of
serve(), specify the key of the environment variable in which the token is set.
// serve.ts
import { serve } from "https://deploy-gitrepo.deno.dev/v0.0.3/serve.ts";
serve({
owner: "your_account_name",
repo: "your_repository_name",
tokenKey: "key_of_token", // The key of the environment variable that stores the personal access token of github. (in short, `Deno.env.get("key_of_token")==="<your_token>"`)
});