-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: outdated endpoint in todo example app (#1344)
* fix: change context -> locals * add Locals global interface * fix endpoint lint errors * fix comment typo * pass Locals to Request in api function * remove resolved TODO * move global Locals -> $lib/types * add comment on how to make it global * add changeset Co-authored-by: Conduitry <git@chor.date>
- Loading branch information
1 parent
f57bf92
commit 5ed3ed2
Showing
5 changed files
with
28 additions
and
13 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 @@ | ||
--- | ||
'create-svelte': patch | ||
--- | ||
|
||
Fix usage of request.locals in starter project |
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,7 @@ | ||
/** | ||
* Can be made globally available by placing this | ||
* inside `global.d.ts` and removing `export` keyword | ||
*/ | ||
export interface Locals { | ||
userid: string; | ||
} |
10 changes: 6 additions & 4 deletions
10
packages/create-svelte/templates/default/src/routes/todos/[uid].json.ts
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 |
---|---|---|
@@ -1,14 +1,16 @@ | ||
import { api } from './_api'; | ||
import type { RequestHandler } from '@sveltejs/kit'; | ||
import type { Locals } from '$lib/types'; | ||
|
||
// PATCH /todos/:uid.json | ||
export const patch = async (request) => { | ||
return api(request, `todos/${request.context.userid}/${request.params.uid}`, { | ||
export const patch: RequestHandler<Locals, FormData> = async (request) => { | ||
return api(request, `todos/${request.locals.userid}/${request.params.uid}`, { | ||
text: request.body.get('text'), | ||
done: request.body.has('done') ? !!request.body.get('done') : undefined | ||
}); | ||
}; | ||
|
||
// DELETE /todos/:uid.json | ||
export const del = async (request) => { | ||
return api(request, `todos/${request.context.userid}/${request.params.uid}`); | ||
export const del: RequestHandler<Locals> = async (request) => { | ||
return api(request, `todos/${request.locals.userid}/${request.params.uid}`); | ||
}; |
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