koajs / discussions

KoaJS Discussions
2 stars 2 forks source link

404 not found for everything #43

Open AshwinTayson opened 6 years ago

AshwinTayson commented 6 years ago

This library doesn't work with the examples given.

Something as simple as

const serve = require('koa-static');

async function images(ctx, next) {
  await next();
  serve('public/images/preview/');
}

app.use(images)

And try to visit localhost:3000/1.png Not found. Please improve the documentation.

hcz commented 5 years ago

You are using koa-static wrong

Try it another way:

const Koa = require('koa');
const serve = require('koa-static');

const STATIC_PATH = 'public/images/preview/';

const app = new Koa();

app.use(serve(STATIC_PATH));
app.listen(3000);
$ curl -I http://localhost:3000/1.png
HTTP/1.1 200 OK
broncha commented 5 years ago

@hcz I have what you said, but I am also getting 404 for all my assets. The contents are being delivered though, just the status code is 400. This is what I have

app.use(koaStatic(public_path, {
   hidden: true,
   setHeaders (res) {
        res.setHeader('content-type', 'text/plain')
    },
}));