Skip to content

Commit

Permalink
Attempt CORS Fix v2
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Hadley <[email protected]>
  • Loading branch information
ahadley1124 committed Dec 18, 2023
1 parent 9916d2f commit 36cea21
Showing 1 changed file with 0 additions and 28 deletions.
28 changes: 0 additions & 28 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,6 @@ async function start() {
}
start();

app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization"
);

// Handle pre-flight requests for CORS
if (req.method === "OPTIONS") {
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
return res.status(200).json({});
}

next();
});

app.get("/", (req, res) => {
res.send("Hello World");
});
Expand Down Expand Up @@ -89,8 +72,6 @@ app.get("/callsigns/:callsign", async (req, res) => {
});

app.post("/qso/:callsign", async (req, res) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET, POST");
let json: QsoData = new QsoData();
json.band = req.body.band;
json.callsign = req.params.callsign;
Expand All @@ -107,16 +88,7 @@ app.post("/qso/:callsign", async (req, res) => {
res.sendStatus(200);
});

//set the options request on all routes to /qso *, whether post or get, to allow any origin to access the api
app.options("/qso/:callsign", (req, res) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET, POST");
res.sendStatus(200);
});

app.get("/qso/:callsign", async (req, res) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET, POST");
const { data, error } = await supabase
.from("qsoData")
.select("*")
Expand Down

0 comments on commit 36cea21

Please sign in to comment.