Skip to content

Commit

Permalink
Remove remaining simple objects usage (#9266)
Browse files Browse the repository at this point in the history
Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
  • Loading branch information
bluwy and natemoo-re authored Dec 1, 2023
1 parent 7cf5e75 commit ac41820
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 23 deletions.
12 changes: 3 additions & 9 deletions examples/ssr/src/pages/api/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ export function GET({ cookies }: APIContext) {
let userId = cookies.get('user-id').value;

if (!userId || !userCartItems.has(userId)) {
return {
body: JSON.stringify({ items: [] }),
};
return Response.json({ items: [] });
}
let items = userCartItems.get(userId);
let array = Array.from(items.values());

return new Response(JSON.stringify({ items: array }));
return Response.json({ items: array });
}

interface AddToCartItem {
Expand All @@ -36,9 +34,5 @@ export async function POST({ cookies, request }: APIContext) {
cart.set(item.id, { id: item.id, name: item.name, count: 1 });
}

return new Response(
JSON.stringify({
ok: true,
})
);
return Response.json({ ok: true });
}
12 changes: 5 additions & 7 deletions examples/ssr/src/pages/login.form.async.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { APIContext, APIRoute } from 'astro';

export const post: APIRoute = ({ cookies, params, request }: APIContext) => {
export const POST: APIRoute = ({ cookies }: APIContext) => {
// add a new cookie
cookies.set('user-id', '1', {
path: '/',
maxAge: 2592000,
});

return {
body: JSON.stringify({
ok: true,
user: 1,
}),
};
return Response.json({
ok: true,
user: 1,
});
};
2 changes: 1 addition & 1 deletion examples/ssr/src/pages/login.form.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { APIContext } from 'astro';

export function post({ cookies, params, request }: APIContext) {
export function POST({ cookies }: APIContext) {
// add a new cookie
cookies.set('user-id', '1', {
path: '/',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ export async function GET() {
const welcomePost = await getEntry('blog', 'welcome');

if (!welcomePost?.data) {
return {
body: { error: 'blog/welcome did not return `data`.' },
}
return Response.json({ error: 'blog/welcome did not return `data`.' }, { status: 404 })
}

const banner = await getEntry(welcomePost.data.banner);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

export function POST() {
return {
body: JSON.stringify({ ok: true })
};
return Response.json({ ok: true });
}

0 comments on commit ac41820

Please sign in to comment.