mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
[ci] format
This commit is contained in:
parent
4ca6a0933d
commit
4392083cca
4 changed files with 13 additions and 14 deletions
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue