Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set CORS of static resources #64

Open
quzhichao opened this issue Sep 26, 2019 · 2 comments
Open

How to set CORS of static resources #64

quzhichao opened this issue Sep 26, 2019 · 2 comments

Comments

@quzhichao
Copy link

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
Copy link

Should probably move cors above the koa-static middleware

@3imed-jaberi
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants