koajs / koajs/cors

How to set CORS of static resources

Open
#64 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
742
Forks
83
PR merge metrics
No merged PRs in 30d

Description

this my config

```js
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.

Contributor guide

Open the contributing guide

Research direction

Start with the two app.use entry points shown in the issue, comparing the koa-static and cors middleware order. Reproduce a request for a file under public and inspect its response headers; done means the intended static-resource response includes the required CORS headers without breaking the stated credentials and origin settings.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.