Skip to content

Commit

Permalink
Fix deno cli script (close #505)
Browse files Browse the repository at this point in the history
  • Loading branch information
ije committed Jan 24, 2023
1 parent e783d12 commit 0ceed80
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ func esmHandler() rex.Handle {
// static routes
switch pathname {
case "/":
// return deno cli script if the `User-Agent` is "Deno"
if strings.HasPrefix(ctx.R.UserAgent(), "Deno/") {
cliTs, err := embedFS.ReadFile("server/embed/deno_cli.ts")
if err != nil {
return err
}
ctx.SetHeader("Content-Type", "application/typescript; charset=utf-8")
return bytes.ReplaceAll(cliTs, []byte("v{VERSION}"), []byte(fmt.Sprintf("v%d", VERSION)))
}
indexHTML, err := embedFS.ReadFile("server/embed/index.html")
if err != nil {
return err
Expand Down
5 changes: 5 additions & 0 deletions test/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ async function runCliTest() {
`{"importMap": "import-map.json"}`,
);

const res = await fetch("http://localhost:8080/");
if (!res.headers.get("content-type")?.startsWith("application/typescript")) {
throw new Error(`Invalid content type: ${res.headers.get("content-type")}`);
}

const { code, success } = await Deno.run({
cmd: [
Deno.execPath(),
Expand Down

0 comments on commit 0ceed80

Please sign in to comment.