koajs / static

Static file server middleware

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Serve static files from a specific URL path?

shumsky opened this issue · comments

Hi,

If I understand correctly, koa-static always serves resources from the root URL (i.e. /). So, if I have a middleware:

const app = new Koa();
app.use(serve('./static'));
app.listen(3000);

then static files inside ./static will be available via http://localhost:3000/path/to/file URL pattern.

But what if I need them to be available from http://localhost:3000/some-prefix/path/to/file? It seems koa-static doesn't allow to configure that. For example, in Spring framework it is possible to do.

What do you think? Would it make sense to add such configuration option?

Hi, @shumsky

for this purpose you can use "koajs/mount Mount koa-static to a specific path"
like this:

app.use(mount('/some-prefix', serve('./static')));

Hi @pasechnik,

Thank you. Didn't know about that module. The question is resolved.