Skip to content

Commit

Permalink
fix: should set access-control-allow-origin and headers (#606)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Nov 3, 2023
1 parent 9ea7008 commit 18ef7f4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/port/controller/package/DownloadPackageVersionTar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export class DownloadPackageVersionTarController extends AbstractController {
method: HTTPMethodEnum.OPTIONS,
})
async downloadForOptions(@Context() ctx: EggContext) {
ctx.set('access-control-allow-origin', '*');
ctx.set('access-control-allow-methods', 'GET,HEAD');
ctx.status = 204;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ describe('test/port/controller/package/DownloadPackageVersionTarController.test.
let res = await app.httpRequest()
.options(`/${name}/-/testmodule-download-version-tar-1.0.0.tgz`);
assert.equal(res.status, 204);
assert.equal(res.headers['access-control-allow-origin'], '*');
assert.equal(res.headers['access-control-allow-methods'], 'GET,HEAD');
res = await app.httpRequest()
.options(`/${scopedName}/-/testmodule-download-version-tar-1.0.0.tgz`);
assert.equal(res.status, 204);
assert.equal(res.headers['access-control-allow-origin'], '*');
assert.equal(res.headers['access-control-allow-methods'], 'GET,HEAD');
});

if (process.env.CNPMCORE_NFS_TYPE !== 'oss') {
Expand Down

0 comments on commit 18ef7f4

Please sign in to comment.