rsnext/packages/next-server/server/serve-static.ts
Tim Neutkens 3e51ddb8af
Move syntax formatting to prettier (#7454)
* Run prettier over packages/**/*.js

* Run prettier over packages/**/*.ts

* Run prettier over examples

* Remove tslint

* Run prettier over examples

* Run prettier over all markdown files

* Run prettier over json files
2019-05-29 13:57:26 +02:00

24 lines
621 B
TypeScript

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)
})
}