[ci] format
This commit is contained in:
parent
ecbcc8c42c
commit
9fa013b4fa
8 changed files with 15 additions and 19 deletions
|
@ -7,9 +7,9 @@ const clientRoot = new URL('../dist/client/', import.meta.url);
|
|||
|
||||
async function handle(req, res) {
|
||||
ssrHandler(req, res, async (err) => {
|
||||
if(err) {
|
||||
if (err) {
|
||||
res.writeHead(500);
|
||||
res.end(err.stack)
|
||||
res.end(err.stack);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,4 @@ import db from './db.json';
|
|||
const products = db.products;
|
||||
const productMap = new Map(products.map((product) => [product.id, product]));
|
||||
|
||||
export {
|
||||
products,
|
||||
productMap
|
||||
};
|
||||
export { products, productMap };
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
|
||||
// Normally this would be in a database.
|
||||
export const userCartItems = new Map();
|
||||
|
|
|
@ -6,15 +6,15 @@ export function get(_params: any, request: Request) {
|
|||
let userId = cookie ? lightcookie.parse(cookie)['user-id'] : '1'; // default for testing
|
||||
if (!userId || !userCartItems.has(userId)) {
|
||||
return {
|
||||
body: JSON.stringify({ items: [] })
|
||||
body: JSON.stringify({ items: [] }),
|
||||
};
|
||||
}
|
||||
let items = userCartItems.get(userId);
|
||||
let array = Array.from(items.values());
|
||||
|
||||
return {
|
||||
body: JSON.stringify({ items: array })
|
||||
}
|
||||
body: JSON.stringify({ items: array }),
|
||||
};
|
||||
}
|
||||
|
||||
interface AddToCartItem {
|
||||
|
@ -41,7 +41,7 @@ export async function post(_params: any, request: Request) {
|
|||
|
||||
return {
|
||||
body: JSON.stringify({
|
||||
ok: true
|
||||
})
|
||||
ok: true,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2,6 +2,6 @@ import { products } from '../../models/db';
|
|||
|
||||
export function get() {
|
||||
return {
|
||||
body: JSON.stringify(products)
|
||||
body: JSON.stringify(products),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -6,12 +6,12 @@ export function get({ id: idStr }) {
|
|||
const product = productMap.get(id);
|
||||
|
||||
return {
|
||||
body: JSON.stringify(product)
|
||||
body: JSON.stringify(product),
|
||||
};
|
||||
} else {
|
||||
return new Response(null, {
|
||||
status: 400,
|
||||
statusText: 'Not found'
|
||||
statusText: 'Not found',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ export function createRequest({ url, headers, method = 'GET', body = undefined,
|
|||
const request = new Request(url.toString(), {
|
||||
method: method,
|
||||
headers: headersObj,
|
||||
body
|
||||
body,
|
||||
});
|
||||
|
||||
Object.defineProperties(request, {
|
||||
|
|
|
@ -129,11 +129,11 @@ async function handleRequest(
|
|||
}
|
||||
|
||||
let body: ArrayBuffer | undefined = undefined;
|
||||
if(!(req.method === 'GET' || req.method === 'HEAD')) {
|
||||
if (!(req.method === 'GET' || req.method === 'HEAD')) {
|
||||
let bytes: string[] = [];
|
||||
await new Promise(resolve => {
|
||||
await new Promise((resolve) => {
|
||||
req.setEncoding('utf-8');
|
||||
req.on('data', bts => bytes.push(bts));
|
||||
req.on('data', (bts) => bytes.push(bts));
|
||||
req.on('close', resolve);
|
||||
});
|
||||
body = new TextEncoder().encode(bytes.join('')).buffer;
|
||||
|
|
Loading…
Reference in a new issue