0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-10 23:01:26 -05:00

Remove remaining simple objects usage (#9266)

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
This commit is contained in:
Bjorn Lu 2023-12-02 00:58:29 +08:00 committed by GitHub
parent 7cf5e7523d
commit ac41820821
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 23 deletions

View file

@ -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 {
@ -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 });
}

View file

@ -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,
});
};

View file

@ -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: '/',

View file

@ -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);

View file

@ -1,6 +1,4 @@
export function POST() {
return {
body: JSON.stringify({ ok: true })
};
return Response.json({ ok: true });
}