Skip to content

Commit

Permalink
Fix ci problem and change http cors check stage in httpHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Jan 7, 2022
1 parent 50e3109 commit 0b85f28
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,16 +371,16 @@ module.exports = {
}
}

const shouldBreak = this.corsHandler(this.settings, req, res);
if(shouldBreak) {
return;
}

try {
const result = await this.actions.rest({ req, res }, options);
if (result == null) {
// Not routed.

const shouldBreak = this.corsHandler(this.settings, req, res);
if(shouldBreak) {
return;
}

// Serve assets static files
if (this.serve) {
this.serve(req, res, err => {
Expand Down Expand Up @@ -880,16 +880,19 @@ module.exports = {

const ctx = req.$ctx;
let responseType = "application/json; charset=utf-8";
if (ctx.meta.$responseType) {
responseType = ctx.meta.$responseType;
}
if (ctx.meta.$responseHeaders) {
Object.keys(ctx.meta.$responseHeaders).forEach(key => {
if (key === "Content-Type" && !responseType)
responseType = ctx.meta.$responseHeaders[key];
else
res.setHeader(key, ctx.meta.$responseHeaders[key]);
});

if (ctx) {
if (ctx.meta.$responseType) {
responseType = ctx.meta.$responseType;
}
if (ctx.meta.$responseHeaders) {
Object.keys(ctx.meta.$responseHeaders).forEach(key => {
if (key === "Content-Type" && !responseType)
responseType = ctx.meta.$responseHeaders[key];
else
res.setHeader(key, ctx.meta.$responseHeaders[key]);
});
}
}

// Return with the error as JSON object
Expand Down

0 comments on commit 0b85f28

Please sign in to comment.