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

(std/file_server): better template #3423

Merged
merged 7 commits into from
Dec 3, 2019
Merged

(std/file_server): better template #3423

merged 7 commits into from
Dec 3, 2019

Conversation

zhmushan
Copy link
Contributor

image
image

@@ -126,7 +81,7 @@ async function serveFile(
const fileInfo = await stat(filePath);
const headers = new Headers();
headers.set("content-length", fileInfo.len.toString());
headers.set("content-type", contentType(extname(filePath)) || "text/plain");
headers.set("content-type", "text/plain");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the behavior we want?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If using contentType(), sometimes the browser will download the file directly

Copy link
Contributor

@kevinkassimo kevinkassimo Nov 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we prefer to open a typescript file instead of downloading it

Copy link
Contributor Author

@zhmushan zhmushan Nov 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhmushan Yeah but that was my intention... I remember Python SimpleHTTPServer/http.server similarly set content types
Ref: https://github.com/python/cpython/blob/305189ecdc8322c22879a04564cad5989f937462/Lib/http/server.py#L694, https://github.com/python/cpython/blob/305189ecdc8322c22879a04564cad5989f937462/Lib/http/server.py#L854-L876

It is a pity that the mime type of typescript has not been determined yet.
Maybe we can do special processing for .ts files.
It seems that content types that start with "application/" all will be downloaded directly.
So I think it is reasonable to set it to "text/plain"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go with the behavior @zhmushan has changed for now - it's quite annoying when browsing files that they get downloaded...

`;
}

// TODO: load files using template
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean? I would opt that you remove this TODO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we don’t need to render markdown/code pages, I will remove this todo

std/http/template.ts Outdated Show resolved Hide resolved
@axetroy
Copy link
Contributor

axetroy commented Nov 30, 2019

If you want to support custom templates

Consider defining a template interface

As long as the template that meets this interface can be used

eg.

interface Template {
  // defined render
  renderFile(): string
  renderFolder(): string
}

class CustomerTemplate implements Template {
  renderFile() {
    //
  }
  renderFolder() {
    //
  }
}

function generateTemplate (tpl Template, tree): string {
 //
}

The interface need to be discussed

May be a bit complicated, but it can be highly abstract

@zhmushan zhmushan requested a review from ry December 2, 2019 16:07
@@ -0,0 +1,111 @@
import { EntryInfo } from "./file_server.ts";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhmushan Please merge this file into file_server.ts - I don't think the extra module is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ry done

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks !

@ry ry merged commit cfa4f54 into denoland:master Dec 3, 2019
@zhmushan zhmushan deleted the file_display branch December 3, 2019 00:14
@ry
Copy link
Member

ry commented Dec 7, 2019

This change reduced the size of the file_server bundle by half! I suppose that's because it no longer needs the content-type database?

Screen Shot 2019-12-07 at 4 27 22 PM

bartlomieju pushed a commit to bartlomieju/deno that referenced this pull request Dec 28, 2019
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 21, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Feb 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants