Skip to content

Commit

Permalink
👀 Trying to add redirect functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
dmdin committed Feb 12, 2025
1 parent 754378c commit b7f172e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,12 @@ export class Composer<T extends { [k: string]: object }> {
result
});
} catch (e) {

if (e?.status?.toString()?.startsWith('3')){
console.log('throw')
throw e
}

(this.config?.onError ?? console.error)(e, req);
return buildError({
code: ErrorCode.InternalError,
Expand Down
13 changes: 13 additions & 0 deletions tests/sveltekit/src/routes/redirectTest/+page.svelte
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>
41 changes: 41 additions & 0 deletions tests/sveltekit/src/routes/redirectTest/+server.ts
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')
}
1 change: 1 addition & 0 deletions tests/sveltekit/src/routes/redirectTest/in/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a href="/redirectTest"></a>

0 comments on commit b7f172e

Please sign in to comment.