export interface IHttpServerOptions { name: string port: number rootFolders: IStringDictionary } export default class HttpServer { private readonly TAG: string private readonly _options: IHttpServerOptions constructor(options: IHttpServerOptions) { this._options = options this.start() } private start() { Deno.serve( {hostname: 'localhost', port: this._options.port}, (request) => { const pathName = new URL(request.url).pathname const pair = Object.entries(this._options.rootFolders) .find(([key, value]) => { return pathName.startsWith(key) }) const rootPath = pair && pair.length == 2 ? `${pair[1]}` : '' if (rootPath.length) { return serveDir(request, { fsRoot: rootPath }) } else { console.log('Unable to match path to static file store', request.url) } return new Response() } ) } }