0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

update SSR example to match recent change on Astro API Context (#4854)

This commit is contained in:
Steven Yung 2022-09-23 18:57:05 +02:00 committed by GitHub
parent 9077073fb4
commit f4edba80f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View file

@ -1,7 +1,8 @@
import { APIContext } from 'astro';
import lightcookie from 'lightcookie';
import { userCartItems } from '../../models/session';
export function get(_params: any, request: Request) {
export function get({ request }: APIContext) {
let cookie = request.headers.get('cookie');
let userId = cookie ? lightcookie.parse(cookie)['user-id'] : '1'; // default for testing
if (!userId || !userCartItems.has(userId)) {
@ -22,7 +23,7 @@ interface AddToCartItem {
name: string;
}
export async function post(_params: any, request: Request) {
export async function post({ request }: APIContext) {
const item: AddToCartItem = await request.json();
let cookie = request.headers.get('cookie');

View file

@ -1,7 +1,8 @@
import { productMap } from '../../../models/db';
import type { APIContext } from 'astro';
export function get({ id: idStr }) {
const id = Number(idStr);
export function get({ params }: APIContext) {
const id = Number(params.id);
if (productMap.has(id)) {
const product = productMap.get(id);