Reputation: 20212
I'm returning a value in JSON for example in one of my endpoints:
{
"image":"http//devservername/assets/someimage.jpg"
}
I'm trying to figure out how to statically serve this through Koa.js and not sure if that's going to be in a route or what...
Upvotes: 1
Views: 3228
Reputation:
Use koa-static
.
npm install --save koa-static
// index.js or whatever
var KoaStatic = require('koa-static');
app.use(KoaStatic('assets'));
This will serve a request for foo.txt
from assets/foo.txt
. If you want to serve assets/foo.txt
in response to a request for assets/foo.txt
, then call KoaStatic('.')
. That is probably not a good idea, since it will serve anything from the root. Better to create a public
directory, put an assets
directory under it, and use KoaStatic('public')
.
Upvotes: 4
Reputation: 196
remove http://devservername
and it will link, ofcourse you should use middleware to serve folders.
use koa-static-folder
import serve from 'koa-static-folder';
serve(__dirname + '/public/');
Upvotes: 0