Skip to content

ayame113/deploy_gitrepo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

deploy_gitrepo

star this repo

This module provides a very simple server for creating github mirroring sites with deno deploy.

What is this?

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.

How to use?

First Step

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",
});

Second Step

Sign up for deno deploy, create a new project, and register serve.ts in "git integration".

Feature

Supports version control of git tags.

  • The URL looks like this: https://<your_domain>/<version>/<path_to_file>
  • Great for delivering Deno modules.

Specify the converters option to convert the content.

  • You can convert markdown to HTML and use it as an alternative to github pages.
// 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 headers property 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,
});

⚠️ Due to the CPU time limit of the deployment, it can be difficult to include markdown conversion and TypeScript conversion at the same time. Both use wasm. This may be resolved at denoland/deploy_feedback#95.

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>"`)
});

Link

github

About

This module provides a very simple server for creating github mirroring sites with deno deploy.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published