silverwolf-x/project / packages /next /src /next-devtools /server /middleware-response.ts
silverwolf-x's picture
download
raw
1.17 kB
import type { ServerResponse } from 'http'
import { inspect } from 'util'
export const middlewareResponse = {
noContent(res: ServerResponse) {
res.statusCode = 204
res.end('No Content')
},
badRequest(res: ServerResponse, reason?: string) {
res.statusCode = 400
if (reason !== undefined) {
res.setHeader('Content-Type', 'text/plain')
res.end(reason)
} else {
res.end()
}
},
notFound(res: ServerResponse) {
res.statusCode = 404
res.end('Not Found')
},
methodNotAllowed(res: ServerResponse) {
res.statusCode = 405
res.end('Method Not Allowed')
},
internalServerError(res: ServerResponse, error?: unknown) {
res.statusCode = 500
res.setHeader('Content-Type', 'text/plain')
res.end(
error !== undefined
? inspect(error, { colors: false })
: 'Internal Server Error'
)
},
json(res: ServerResponse, data: any) {
res
.setHeader('Content-Type', 'application/json')
.end(Buffer.from(JSON.stringify(data)))
},
jsonString(res: ServerResponse, data: string) {
res.setHeader('Content-Type', 'application/json').end(Buffer.from(data))
},
}

Xet Storage Details

Size:
1.17 kB
·
Xet hash:
5437203793457881b9fb162657ab2cfc62a6a2380988a04609e690dd28a26888

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.