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:
parent
9077073fb4
commit
f4edba80f9
2 changed files with 6 additions and 4 deletions
|
@ -1,7 +1,8 @@
|
||||||
|
import { APIContext } from 'astro';
|
||||||
import lightcookie from 'lightcookie';
|
import lightcookie from 'lightcookie';
|
||||||
import { userCartItems } from '../../models/session';
|
import { userCartItems } from '../../models/session';
|
||||||
|
|
||||||
export function get(_params: any, request: Request) {
|
export function get({ request }: APIContext) {
|
||||||
let cookie = request.headers.get('cookie');
|
let cookie = request.headers.get('cookie');
|
||||||
let userId = cookie ? lightcookie.parse(cookie)['user-id'] : '1'; // default for testing
|
let userId = cookie ? lightcookie.parse(cookie)['user-id'] : '1'; // default for testing
|
||||||
if (!userId || !userCartItems.has(userId)) {
|
if (!userId || !userCartItems.has(userId)) {
|
||||||
|
@ -22,7 +23,7 @@ interface AddToCartItem {
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function post(_params: any, request: Request) {
|
export async function post({ request }: APIContext) {
|
||||||
const item: AddToCartItem = await request.json();
|
const item: AddToCartItem = await request.json();
|
||||||
|
|
||||||
let cookie = request.headers.get('cookie');
|
let cookie = request.headers.get('cookie');
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import { productMap } from '../../../models/db';
|
import { productMap } from '../../../models/db';
|
||||||
|
import type { APIContext } from 'astro';
|
||||||
|
|
||||||
export function get({ id: idStr }) {
|
export function get({ params }: APIContext) {
|
||||||
const id = Number(idStr);
|
const id = Number(params.id);
|
||||||
if (productMap.has(id)) {
|
if (productMap.has(id)) {
|
||||||
const product = productMap.get(id);
|
const product = productMap.get(id);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue