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

Vercel routing defaults #3820

Merged
merged 2 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/heavy-donuts-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Pass trailingSlash config to adapters
5 changes: 5 additions & 0 deletions .changeset/modern-grapes-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-vercel': patch
---

Clean URLs and handle trailingSlash configuration
78 changes: 78 additions & 0 deletions packages/adapter-vercel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,83 @@ import esbuild from 'esbuild';

const dir = '.vercel_build_output';

// rules for clean URLs and trailing slash handling,
// generated with @vercel/routing-utils
const redirects = {
always: [
{
src: '^/(?:(.+)/)?index(?:\\.html)?/?$',
headers: {
Location: '/$1/'
},
status: 308
},
{
src: '^/(.*)\\.html/?$',
headers: {
Location: '/$1/'
},
status: 308
},
{
src: '^/\\.well-known(?:/.*)?$'
},
{
src: '^/((?:[^/]+/)*[^/\\.]+)$',
headers: {
Location: '/$1/'
},
status: 308
},
{
src: '^/((?:[^/]+/)*[^/]+\\.\\w+)/$',
headers: {
Location: '/$1'
},
status: 308
}
],
never: [
{
src: '^/(?:(.+)/)?index(?:\\.html)?/?$',
headers: {
Location: '/$1'
},
status: 308
},
{
src: '^/(.*)\\.html/?$',
headers: {
Location: '/$1'
},
status: 308
},
{
src: '^/(.*)/$',
headers: {
Location: '/$1'
},
status: 308
}
],
ignore: [
{
src: '^/(?:(.+)/)?index(?:\\.html)?/?$',
headers: {
Location: '/$1'
},
status: 308
},
{
src: '^/(.*)\\.html/?$',
headers: {
Location: '/$1'
},
status: 308
}
]
};

/** @type {import('.')} **/
export default function ({ external = [] } = {}) {
return {
Expand Down Expand Up @@ -69,6 +146,7 @@ export default function ({ external = [] } = {}) {
writeFileSync(
`${dir}/config/routes.json`,
JSON.stringify([
...redirects[builder.trailingSlash],
{
src: `/${builder.appDir}/.+`,
headers: {
Expand Down
1 change: 1 addition & 0 deletions packages/kit/src/core/adapt/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function create_builder({ cwd, config, build_data, log }) {
copy,

appDir: config.kit.appDir,
trailingSlash: config.kit.trailingSlash,

createEntries(fn) {
generated_manifest = true;
Expand Down
1 change: 1 addition & 0 deletions packages/kit/types/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface Builder {
mkdirp(dir: string): void;

appDir: string;
trailingSlash: 'always' | 'never' | 'ignore';

/**
* Create entry points that map to individual functions
Expand Down