Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
rtritto committed Oct 22, 2024
1 parent 9962d8f commit 6a0f80a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/vike-node/src/runtime/adapters/connectToWebUws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function connectToWeb(handler: ConnectMiddlewareUws): WebHandlerUws {
for (const [key, value] of headers) {
res.writeHeader(key, value)
}
if(statusCodesWithoutBody.has(statusCode)) {
if (statusCodesWithoutBody.has(statusCode)) {
res.end()
} else {
res.end(await readableStreamToBuffer(Readable.toWeb(readable) as ReadableStream))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import type { OutgoingHttpHeader, OutgoingHttpHeaders } from 'node:http'
import { PassThrough, Readable } from 'node:stream'
import type { HttpResponse } from 'uWebSockets.js'

type OnReadable = (cb: (result: {
readable: Readable
headers: [string, string][]
statusCode: number
}) => void) => void
type OnReadable = (
cb: (result: {
readable: Readable
headers: [string, string][]
statusCode: number
}) => void
) => void

type CreatedServerReponse = {
res: HttpResponse
Expand Down
6 changes: 3 additions & 3 deletions packages/vike-node/src/runtime/frameworks/uws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import type { PlatformRequestUws, VikeOptions } from '../types.js'
*/
function vike(app: TemplatedApp, options?: VikeOptions<HttpRequest>): TemplatedApp {
const handler = createHandler(options)
return app.get('*', (response, request) =>
return app.get('*', (response, request) =>
handler({ response, request, platformRequest: request as PlatformRequestUws }).catch((error: Error) => {
console.error(error)
response.writeStatus('500').end('Internal Server Error: ' + error.message)
console.error(error)
response.writeStatus('500').end('Internal Server Error: ' + error.message)
})
)
}
12 changes: 9 additions & 3 deletions packages/vike-node/src/runtime/handler-node-only-uws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export function createHandler(options: VikeOptions<PlatformRequestUws> = {}) {
// let staticMiddleware: ConnectMiddleware | undefined
// let compressMiddleware: ConnectMiddleware | undefined

return async function handler({ res, platformRequest }: {
return async function handler({
res,
platformRequest
}: {
res: HttpResponse
platformRequest: PlatformRequestUws
}): Promise<void> {
Expand All @@ -35,7 +38,6 @@ export function createHandler(options: VikeOptions<PlatformRequestUws> = {}) {
// if (shouldCompressResponse) {
// await applyCompression(req, res, shouldCache)
// }

// if (staticConfig) {
// const handled = await serveStaticFiles(req, res, staticConfig)
// if (handled) return true
Expand Down Expand Up @@ -87,7 +89,11 @@ function handleViteDevServer(res: HttpResponse, platformRequest: PlatformRequest
return new Promise<boolean>((resolve) => {
res.once('close', () => resolve(true))
assert(globalStore.viteDevServer)
globalStore.viteDevServer.middlewares(platformRequest as unknown as IncomingMessage, res as unknown as ServerResponse, () => resolve(false))
globalStore.viteDevServer.middlewares(
platformRequest as unknown as IncomingMessage,
res as unknown as ServerResponse,
() => resolve(false)
)
})
}

Expand Down
6 changes: 2 additions & 4 deletions packages/vike-node/src/runtime/handler-web-and-node-uws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { HttpRequest, HttpResponse } from 'uWebSockets.js'
import { isNodeLike } from '../utils/isNodeLike.js'
import { connectToWeb } from './adapters/connectToWebUws.js'
import { createHandler as createHandlerNode } from './handler-node-only-uws.js'
import { createHandler as createHandlerWeb } from'./handler-web-only-uws.js'
import { createHandler as createHandlerWeb } from './handler-web-only-uws.js'
import type { HandlerUws, PlatformRequestUws, VikeOptions } from './types.js'

const getHeaders = (req: HttpRequest): [string, string][] => {
Expand Down Expand Up @@ -38,9 +38,7 @@ export function createHandler<HttpRequest>(options: VikeOptions<HttpRequest> = {
if (await isNodeLike()) {
const nodeOnlyHandler = createHandlerNode(options)
const nodeHandler: HandlerUws<PlatformRequestUws> = ({ platformRequest }) => {
const connectedHandler = connectToWeb((res, platformRequest) =>
nodeOnlyHandler({ res, platformRequest })
)
const connectedHandler = connectToWeb((res, platformRequest) => nodeOnlyHandler({ res, platformRequest }))
return connectedHandler(response, platformRequest)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vike-node/src/runtime/utils/writeHttpResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ async function readableStreamToBuffer(readableStream: ReadableStream): Promise<B
}

// Using Buffer.concat directly to handle chunk concatenation, improving performance.
return Buffer.concat(chunks.map(chunk => Buffer.from(chunk)))
return Buffer.concat(chunks.map((chunk) => Buffer.from(chunk)))
}
2 changes: 1 addition & 1 deletion packages/vike-node/src/runtime/vike-handler-uws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function renderPageWeb<PlatformRequest>({
platformRequest,
options
}: {
res: HttpResponse,
res: HttpResponse
url: string
headers: [string, string][]
platformRequest: PlatformRequest
Expand Down

0 comments on commit 6a0f80a

Please sign in to comment.