Skip to content

Commit

Permalink
restore cors header injection from #4171, run [npm travis] (#4255)
Browse files Browse the repository at this point in the history
* fix: restore cors header injection from #4171

* tests: move test into describe

* prettier
  • Loading branch information
calebcartwright committed Dec 5, 2021
1 parent b53ac49 commit 38c1e2d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,12 @@ class Server {
const { apiProvider: githubApiProvider } = this.githubConstellation
setRoutes(allowedOrigin, githubApiProvider, camp)

// https://github.com/badges/shields/issues/3273
camp.handle((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*')
next()
})

this.registerErrorHandlers()
this.registerRedirects()
await this.registerServices()
Expand Down
12 changes: 12 additions & 0 deletions core/server/server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ describe('The server', function () {
expect(headers['cache-control']).to.equal('max-age=3600, s-maxage=3600')
})

it('should return cors header for the request', async function () {
const { statusCode, headers } = await got(`${baseUrl}npm/v/express.svg`)
expect(statusCode).to.equal(200)
expect(headers['access-control-allow-origin']).to.equal('*')
})

it('should redirect colorscheme PNG badges as configured', async function () {
const { statusCode, headers } = await got(
`${baseUrl}:fruit-apple-green.png`,
Expand Down Expand Up @@ -201,6 +207,12 @@ describe('The server', function () {
.and.to.include('410')
.and.to.include('jpg no longer available')
})

it('should return cors header for the request', async function () {
const { statusCode, headers } = await got(`${baseUrl}npm/v/express.svg`)
expect(statusCode).to.equal(200)
expect(headers['access-control-allow-origin']).to.equal('*')
})
})

context('`requireCloudflare` is enabled', function () {
Expand Down

0 comments on commit 38c1e2d

Please sign in to comment.