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

Fix/issue 463 pretty urls in prodServer #464

Merged
merged 7 commits into from
Dec 31, 2020

Conversation

hutchgrant
Copy link
Member

@hutchgrant hutchgrant commented Dec 31, 2020

Related Issue

#463

Summary of Changes

  • remove url redirect from prodServer in serve lifecycle.
  • refactor prodServer slightly

@hutchgrant hutchgrant changed the title task: remove the url redirect from serve lifecycle Fix/issue 463 pretty urls in prodServer Dec 31, 2020
@hutchgrant hutchgrant added the CLI label Dec 31, 2020
@thescientist13 thescientist13 linked an issue Dec 31, 2020 that may be closed by this pull request
5 tasks
@thescientist13 thescientist13 added the enhancement Improve something existing (e.g. no docs, new APIs, etc) label Dec 31, 2020
@@ -69,7 +69,9 @@ function getProdServer(compilation) {
const { outputDir } = compilation.context;

if (ctx.request.url.endsWith('/')) {
ctx.redirect(`http://localhost:8080${ctx.request.url}index.html`);
const contents = await fsp.readFile(path.join(outputDir, ctx.request.url, 'index.html'), 'utf-8');
Copy link
Member

Choose a reason for hiding this comment

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

Does combining the / and .html tests not work well together?

if (ctx.request.url.endsWith('/')) {
  const contents = await fsp.readFile(path.join(outputDir, ctx.request.url, 'index.html'), 'utf-8');
  ctx.set('Content-Type', 'text/html');
  ctx.body = contents;
}

Or I suppose it could also make sense to keep .html as a stand alone handler as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

right I think need to keep it in case?

Copy link
Member

Choose a reason for hiding this comment

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

right I think need to keep it in case?

in case of what though? I wasn't sure if you had a case in mind, so the question was mostly for you. ;)

What cases do we have of needing to process .html differently? I could at least see treating both with the same logic perhaps?

if (ctx.request.url.endsWith('/') || ctx.request.url.endsWith('.html')) {
  const barePath = url.endsWith('/') ? '' : ctx.request.url;
  const contents = await fsp.readFile(path.join(outputDir, barePath, 'index.html'), 'utf-8');

  ctx.set('Content-Type', 'text/html');
  ctx.body = contents;
}

Mostly just spitballing at this point, so no big deal.

Copy link
Member Author

Choose a reason for hiding this comment

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

lets go with that then. I don't have an immediate use case are we resolving all custom html files to their own routes and prettifying them ? e.g. docs.html would just be /docs/ ? I don't know I havent tested that yet.

Copy link
Member

Choose a reason for hiding this comment

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

yeah, give it a test. At the end of the day they both return the contents of an HTML file, it's just that we can do it simply without including a redirect in either case.

@hutchgrant
Copy link
Member Author

did a quick refactor as well.

@thescientist13 thescientist13 merged commit 595b04b into release/0.10.0 Dec 31, 2020
@thescientist13 thescientist13 deleted the fix/issue-463-pretty-urls-prodserver branch December 31, 2020 23:00
thescientist13 pushed a commit that referenced this pull request Apr 3, 2021
* task: remove the url redirect from serve lifecycle

* fix: remove redundant case

* fix: accomodate present files with .html in pathname

* fix: typo

* fix: correct path

* fix: combine html/prettified url case

* fix: small refactor
thescientist13 pushed a commit that referenced this pull request Apr 3, 2021
* task: remove the url redirect from serve lifecycle

* fix: remove redundant case

* fix: accomodate present files with .html in pathname

* fix: typo

* fix: correct path

* fix: combine html/prettified url case

* fix: small refactor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI enhancement Improve something existing (e.g. no docs, new APIs, etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use pretty urls in mock prodServer
2 participants