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

dev/preview paths #2189

Merged
merged 20 commits into from
Aug 13, 2021
Merged

dev/preview paths #2189

merged 20 commits into from
Aug 13, 2021

Conversation

Rich-Harris
Copy link
Member

following up #2145 (comment)

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpx changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Aug 13, 2021

🦋 Changeset detected

Latest commit: 311303c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Rich-Harris Rich-Harris marked this pull request as draft August 13, 2021 14:18
@Rich-Harris
Copy link
Member Author

This is mostly done, but we're sort of blocked by vitejs/vite#2009 — because the asset path used by __vitePreload is hardcoded, it will preload JS and CSS from the wrong location.

@Rich-Harris
Copy link
Member Author

Also, need to update the docs

@Rich-Harris
Copy link
Member Author

One thing I missed somehow is that we're still not actually serving the app on the basepath during dev and preview. Working on that

@Rich-Harris
Copy link
Member Author

Ok, this is basically done apart from docs, I think. I don't think vitejs/vite#2009 should block us, since it's not a regression — it just means that if you're using assets you will experience errors in svelte-kit preview.

@Rich-Harris
Copy link
Member Author

will do docs after lunch

handle: hooks.handle || (({ request, resolve }) => resolve(request)),
serverFetch: hooks.serverFetch || fetch
const rendered =
parsed.pathname.startsWith(config.kit.paths.base) &&
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if you could create a variable for parsed.pathname.startsWith(config.kit.paths.base) to avoid prettier indenting all the subsequent lines

Copy link
Member Author

Choose a reason for hiding this comment

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

it won't make any difference, it could be x && and prettier would still put them on separate lines

Copy link
Member

Choose a reason for hiding this comment

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

Ah. You could change it like this to avoid the extra indentation:

				if (!parsed.pathname.startsWith(config.kit.paths.base)) {
					res.statusCode = 404;
					res.end('Not found');
					return;
				}
				const rendered = await respond(

Copy link
Member Author

Choose a reason for hiding this comment

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

we could, i just don't love the duplication of

res.statusCode = 404;
res.end('Not found');

maybe it's the lesser of two evils. not sure

Copy link
Member

Choose a reason for hiding this comment

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

could refactor that out:

function not_found(res) {
  res.statusCode = 404;
  res.end('Not found');
}
if (!parsed.pathname.startsWith(config.kit.paths.base)) {
  return not_found(res);
}

@benmccann
Copy link
Member

Nice! This looks like it cleans some stuff up a bit

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.

3 participants