Skip to content

Commit

Permalink
feat: local cors (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
thantos authored Jul 24, 2023
1 parent 404dff2 commit fd913c2
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/@eventual/cli/src/commands/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,24 @@ export const local = (yargs: Argv) =>
});

app.use(express.json({ strict: false, limit: maxBodySize }));
// CORS for local
app.use((req, res, next) => {
next();

const headers = res.getHeaders();
if (!headers["Access-Control-Allow-Origin"]) {
res.header("Access-Control-Allow-Origin", req.headers.origin ?? "*");
}
if (!headers["Access-Control-Allow-Methods"]) {
res.header("Access-Control-Allow-Methods", "*");
}
if (!headers["Access-Control-Allow-Headers"]) {
res.header("Access-Control-Allow-Headers", "*");
}
if (!headers["Access-Control-Allow-Credentials"]) {
res.header("Access-Control-Allow-Credentials", "true");
}
});

// open up all of the user and service commands to the service.
app.all("/*", async (req, res) => {
Expand Down

0 comments on commit fd913c2

Please sign in to comment.