koajs / cors

Cross-Origin Resource Sharing(CORS) for koa
Other
732 stars 82 forks source link

How to set CORS of static resources #64

Open quzhichao opened 4 years ago

quzhichao commented 4 years ago

this my config

app.use(convert(require('koa-static')(__dirname + '/public')))
app.use(cors({
  origin: function (ctx) {
    return '*'; 
  },
  exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'],
  maxAge: 5,
  credentials: true,
  allowMethods: ['GET', 'POST', 'DELETE'],
  allowHeaders: ['Content-Type', 'Authorization', 'Accept'],
}))

Error reporting when I access files under public has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

rohit-gohri commented 4 years ago

Should probably move cors above the koa-static middleware

3imed-jaberi commented 3 years ago

It's work fine. you don't need to use convert !!