1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/packages/next-server/server/serve-static.ts

21 lines
609 B
TypeScript
Raw Normal View History

import {IncomingMessage, ServerResponse} from 'http'
import send from 'send'
// since send doesn't support wasm yet
send.mime.define({ 'application/wasm': ['wasm'] })
export function serveStatic(req: IncomingMessage, res: ServerResponse, path: string): Promise<void> {
return new Promise((resolve, reject) => {
send(req, path)
.on('directory', () => {
// We don't allow directories to be read.
const err: any = new Error('No directory access')
err.code = 'ENOENT'
reject(err)
})
.on('error', reject)
.pipe(res)
.on('finish', resolve)
})
}