Skip to content

Commit

Permalink
feat(vite-plugin-nitro): add server event to load function and types (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonroberts authored Aug 26, 2023
1 parent 1c045fd commit b69987a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion apps/analog-app/src/app/pages/(home).server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { setCookie } from 'h3';
import { PageServerLoad } from '@analogjs/router';

import { Product } from '../products';

export const load = async ({ fetch }: PageServerLoad) => {
export const load = async ({ fetch, event }: PageServerLoad) => {
setCookie(event, 'test', 'test');
const products = await fetch<Product[]>('/api/v1/products');

return {
Expand Down
9 changes: 8 additions & 1 deletion apps/analog-app/src/app/pages/shipping/index.server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
export const load = async () => {
import { parseCookies } from 'h3';
import { PageServerLoad } from '@analogjs/router';

export const load = async ({ event }: PageServerLoad) => {
console.log('shipping');
const cookies = parseCookies(event);

console.log('test cookie', cookies['test']);

return {
shipping: true,
};
Expand Down
3 changes: 2 additions & 1 deletion packages/router/src/lib/route-types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { H3Event, H3EventContext } from 'h3';
import { $Fetch } from 'nitropack';
import type { $Fetch } from 'nitropack';

export type PageServerLoad = {
params: H3EventContext['params'];
req: H3Event['node']['req'];
res: H3Event['node']['res'];
fetch: $Fetch;
event: H3Event;
};

export type LoadResult<
Expand Down
3 changes: 2 additions & 1 deletion packages/vite-plugin-nitro/src/lib/plugins/page-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export function pageEndpointsPlugin() {
params: event.context.params,
req: event.node.req,
res: event.node.res,
fetch: $fetch
fetch: $fetch,
event
});
} catch(e) {
console.error(\` An error occurred: \$\{e\}\`)
Expand Down

0 comments on commit b69987a

Please sign in to comment.