-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👀 Trying to add redirect functionality
- Loading branch information
Showing
4 changed files
with
61 additions
and
0 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
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,13 @@ | ||
<script lang="ts"> | ||
import {client} from '../../../../../../rpc/src/client' | ||
import type { Client } from './+server'; | ||
export let data; | ||
const rpc = client<Client>({endpoint: '/redirectTest'}) | ||
let res = ''; | ||
</script> | ||
|
||
|
||
<button on:click={() => rpc.Crud.ping()}>Call redirect</button> |
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,41 @@ | ||
import { json } from '@sveltejs/kit'; | ||
import { Composer, rpc, depends } from '../../../../../src/'; | ||
import { sveltekitMiddleware } from '../../../../../src/middlewares'; | ||
import { redirect } from '@sveltejs/kit'; | ||
|
||
|
||
class Crud { | ||
|
||
@rpc() | ||
pong() { | ||
return 'pong' | ||
} | ||
|
||
@rpc() | ||
async ping() { | ||
throw redirect(303, '/redirectTest/in') | ||
} | ||
} | ||
|
||
// function testMode() { | ||
// return async function h(event, ctx, next) { | ||
// console.log(event, ctx, ) | ||
// return buildResponse({request: event.raw, result: 'hello!!!!'}) | ||
// } | ||
// } | ||
|
||
|
||
|
||
|
||
const composer = Composer.init({ Crud: new Crud() }); | ||
|
||
composer.use(sveltekitMiddleware()); | ||
|
||
export type Client = typeof composer.clientType; | ||
|
||
|
||
export async function POST(event) { | ||
// event.locals.username = event.cookies.get('username') | ||
// return json(await composer.exec(event)); | ||
throw redirect(303, '/redirectTest/in') | ||
} |
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 @@ | ||
<a href="/redirectTest"></a> |