BOLLB
Denoβ€’14mo agoβ€’
5 replies
BOLL

FileServer from tutorial, 2000+ ms to connect?

Hello! I used this guide as an example, and made a small file server.
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()
            }
        )
    }
}

My problem is that when I load files from it, most of the requests takes 2000+ms to connect. The transfer itself is fast, just a few ms, but the initial connection has this big delay. I'm not sure what I have done that might cause this πŸ˜…
image.png
Deno
In-depth documentation, guides, and reference materials for building secure, high-performance JavaScript and TypeScript applications with Deno
Write a file server
Was this page helpful?