diff --git a/packages/astro/src/core/app/node.ts b/packages/astro/src/core/app/node.ts index 11d93013ee..cb5356f630 100644 --- a/packages/astro/src/core/app/node.ts +++ b/packages/astro/src/core/app/node.ts @@ -14,7 +14,7 @@ function createRequestFromNodeRequest(req: IncomingMessage, body?: string): Requ let request = new Request(url, { method: req.method || 'GET', headers: new Headers(entries), - body + body, }); if (req.socket?.remoteAddress) { Reflect.set(request, clientAddressSymbol, req.socket.remoteAddress); @@ -27,23 +27,23 @@ export class NodeApp extends App { return super.match(req instanceof Request ? req : createRequestFromNodeRequest(req)); } render(req: IncomingMessage | Request) { - if('on' in req) { + if ('on' in req) { let body: string | undefined = undefined; let reqBodyComplete = new Promise((resolve, reject) => { - req.on('data', d => { - if(body === undefined) { + req.on('data', (d) => { + if (body === undefined) { body = ''; } - if(d instanceof Buffer) { + if (d instanceof Buffer) { body += d.toString('utf-8'); - } else if(typeof d === 'string') { + } else if (typeof d === 'string') { body += d; } }); req.on('end', () => { resolve(body); }); - req.on('error', err => { + req.on('error', (err) => { reject(err); }); }); diff --git a/packages/integrations/node/src/server.ts b/packages/integrations/node/src/server.ts index 453ecb2d23..12fcf04484 100644 --- a/packages/integrations/node/src/server.ts +++ b/packages/integrations/node/src/server.ts @@ -29,8 +29,8 @@ export function createExports(manifest: SSRManifest) { } else if (next) { return next(); } - } catch(err: unknown) { - if(!res.headersSent) { + } catch (err: unknown) { + if (!res.headersSent) { res.writeHead(500, `Server error`); res.end(); } diff --git a/packages/integrations/node/test/api-route.test.js b/packages/integrations/node/test/api-route.test.js index 963e0463aa..a28b88e7f3 100644 --- a/packages/integrations/node/test/api-route.test.js +++ b/packages/integrations/node/test/api-route.test.js @@ -2,7 +2,6 @@ import nodejs from '../dist/index.js'; import { loadFixture, createRequestAndResponse, toPromise } from './test-utils.js'; import { expect } from 'chai'; - describe('API routes', () => { /** @type {import('./test-utils').Fixture} */ let fixture; @@ -23,13 +22,13 @@ describe('API routes', () => { let { req, res, done } = createRequestAndResponse({ method: 'POST', - url: '/recipes' + url: '/recipes', }); handler(req, res); req.send(JSON.stringify({ id: 2 })); - let [ buffer ] = await done; + let [buffer] = await done; let json = JSON.parse(buffer.toString('utf-8')); expect(json.length).to.equal(1); expect(json[0].name).to.equal('Broccoli Soup'); diff --git a/packages/integrations/node/test/test-utils.js b/packages/integrations/node/test/test-utils.js index 4bd42d557e..0859c6acdb 100644 --- a/packages/integrations/node/test/test-utils.js +++ b/packages/integrations/node/test/test-utils.js @@ -23,7 +23,7 @@ export function createRequestAndResponse(reqOptions) { let res = httpMocks.createResponse({ eventEmitter: EventEmitter, - req + req, }); let done = toPromise(res); @@ -32,7 +32,7 @@ export function createRequestAndResponse(reqOptions) { } export function toPromise(res) { - return new Promise(resolve => { + return new Promise((resolve) => { res.on('end', () => { let chunks = res._getChunks(); resolve(chunks);