From 9fa013b4fa04dc65b9abd75d75865bcbfd609170 Mon Sep 17 00:00:00 2001 From: matthewp Date: Tue, 29 Mar 2022 12:19:10 +0000 Subject: [PATCH] [ci] format --- examples/ssr/server/server.mjs | 4 ++-- examples/ssr/src/models/db.ts | 5 +---- examples/ssr/src/models/session.ts | 1 - examples/ssr/src/pages/api/cart.ts | 10 +++++----- examples/ssr/src/pages/api/products.ts | 2 +- examples/ssr/src/pages/api/products/[id].ts | 4 ++-- packages/astro/src/core/request.ts | 2 +- packages/astro/src/vite-plugin-astro-server/index.ts | 6 +++--- 8 files changed, 15 insertions(+), 19 deletions(-) diff --git a/examples/ssr/server/server.mjs b/examples/ssr/server/server.mjs index 9838d7ada..d7a0a7a40 100644 --- a/examples/ssr/server/server.mjs +++ b/examples/ssr/server/server.mjs @@ -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; } diff --git a/examples/ssr/src/models/db.ts b/examples/ssr/src/models/db.ts index d9caa8b03..0ec181f9a 100644 --- a/examples/ssr/src/models/db.ts +++ b/examples/ssr/src/models/db.ts @@ -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 }; diff --git a/examples/ssr/src/models/session.ts b/examples/ssr/src/models/session.ts index 60ca8f1da..16dce00b4 100644 --- a/examples/ssr/src/models/session.ts +++ b/examples/ssr/src/models/session.ts @@ -1,3 +1,2 @@ - // Normally this would be in a database. export const userCartItems = new Map(); diff --git a/examples/ssr/src/pages/api/cart.ts b/examples/ssr/src/pages/api/cart.ts index 5dbe5acbd..3d7dd6da0 100644 --- a/examples/ssr/src/pages/api/cart.ts +++ b/examples/ssr/src/pages/api/cart.ts @@ -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, + }), }; } diff --git a/examples/ssr/src/pages/api/products.ts b/examples/ssr/src/pages/api/products.ts index 533bdef23..171291004 100644 --- a/examples/ssr/src/pages/api/products.ts +++ b/examples/ssr/src/pages/api/products.ts @@ -2,6 +2,6 @@ import { products } from '../../models/db'; export function get() { return { - body: JSON.stringify(products) + body: JSON.stringify(products), }; } diff --git a/examples/ssr/src/pages/api/products/[id].ts b/examples/ssr/src/pages/api/products/[id].ts index 6a3a83722..d3cc5e42f 100644 --- a/examples/ssr/src/pages/api/products/[id].ts +++ b/examples/ssr/src/pages/api/products/[id].ts @@ -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', }); } } diff --git a/packages/astro/src/core/request.ts b/packages/astro/src/core/request.ts index 6594621a1..e94f1372b 100644 --- a/packages/astro/src/core/request.ts +++ b/packages/astro/src/core/request.ts @@ -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, { diff --git a/packages/astro/src/vite-plugin-astro-server/index.ts b/packages/astro/src/vite-plugin-astro-server/index.ts index 250122d7b..4a5b1a5fc 100644 --- a/packages/astro/src/vite-plugin-astro-server/index.ts +++ b/packages/astro/src/vite-plugin-astro-server/index.ts @@ -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;