-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] allow +server.js files next to +page files (#6773)
* [feat] allow +server.js files next to +page files Closes #5896 * Update packages/kit/src/runtime/server/endpoint.js Co-authored-by: Rich Harris <richard.a.harris@gmail.com> * simplify rules and document them * adjust builder type * Update documentation/docs/06-form-actions.md Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> * link * remove unused type * move docs to +server.js section Co-authored-by: Rich Harris <richard.a.harris@gmail.com> Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> Co-authored-by: Rich Harris <hello@rich-harris.dev>
- Loading branch information
1 parent
6234c07
commit 9ef548a
Showing
11 changed files
with
143 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/kit': patch | ||
--- | ||
|
||
[feat] allow +server.js files next to +page files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/kit/test/apps/basics/src/routes/routing/endpoint-next-to-page/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<script> | ||
let result; | ||
/** @param {string} method */ | ||
async function request(method) { | ||
result = 'loading'; | ||
const response = await fetch('/routing/endpoint-next-to-page', {method}); | ||
result = await response.text(); | ||
} | ||
</script> | ||
|
||
<p>Hi</p> | ||
<button on:click={() => request('GET')}>GET</button> | ||
<button on:click={() => request('PUT')}>PUT</button> | ||
<button on:click={() => request('PATCH')}>PATCH</button> | ||
<button on:click={() => request('POST')}>POST</button> | ||
<button on:click={() => request('DELETE')}>DELETE</button> | ||
<pre>{result}</pre> |
24 changes: 24 additions & 0 deletions
24
packages/kit/test/apps/basics/src/routes/routing/endpoint-next-to-page/+server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** @type {import('./$types').RequestHandler} */ | ||
export function GET() { | ||
return new Response('GET'); | ||
} | ||
|
||
/** @type {import('./$types').RequestHandler} */ | ||
export function PUT() { | ||
return new Response('PUT'); | ||
} | ||
|
||
/** @type {import('./$types').RequestHandler} */ | ||
export function PATCH() { | ||
return new Response('PATCH'); | ||
} | ||
|
||
/** @type {import('./$types').RequestHandler} */ | ||
export function POST() { | ||
return new Response('POST'); | ||
} | ||
|
||
/** @type {import('./$types').RequestHandler} */ | ||
export function DELETE() { | ||
return new Response('DELETE'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9ef548a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+actions.server.js
was shifted to+page.server.js
. Don't you think same should be done to+server.js
?9ef548a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current commit is also awesome for my workflow. Above comment is just an idea .