Add support for registering vendor asset routes
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-07-07 22:50:48 -05:00
parent 39d97d6e14
commit e33d8dee8f
10 changed files with 142 additions and 14 deletions

View File

@@ -1,6 +1,7 @@
import {ResponseFactory} from './ResponseFactory'
import {Request} from '../lifecycle/Request'
import {ErrorWithContext, UniversalPath} from '../../util'
import {Logging} from '../../service/Logging'
/**
* Helper function that creates a FileResponseFactory for the given path.
@@ -28,6 +29,7 @@ export class FileResponseFactory extends ResponseFactory {
})
}
request.make<Logging>(Logging).debug(`Setting Content-Type of ${this.path} to ${this.path.contentType}...`)
request.response.setHeader('Content-Type', this.path.contentType || 'application/octet-stream')
request.response.setHeader('Content-Length', String(await this.path.sizeInBytes()))
request.response.body = await this.path.readStream()

View File

@@ -156,6 +156,15 @@ export function staticServer(options: StaticServerOptions = {}): RouteHandler {
// If the resolved path is a directory, send the directory listing response
if ( await filePath.isDirectory() ) {
if ( !options.directoryListing ) {
throw new StaticServerHTTPError(HTTPStatus.NOT_FOUND, 'File not found', {
basePath: basePath.toString(),
filePath: filePath.toString(),
route: route.path,
reason: 'Path is a directory, and directory listing is disabled',
})
}
if ( !route.path.endsWith('/') ) {
return redirect(`${route.path}/`)
}