Skip to content

Commit

Permalink
add cors stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
svalencia014 committed Dec 18, 2023
1 parent 80e909b commit b1a1f64
Showing 1 changed file with 21 additions and 28 deletions.
49 changes: 21 additions & 28 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import cors from "cors";
import dotenv from "dotenv";
import express from "express";
import bodyParser from "body-parser";
import { QsoData } from "./types/QsoData";
import { XMLParser } from "fast-xml-parser";
import { supabase } from "./lib/supabaseClient";
import { LicenseData } from "./types/LicenseData";
import cors from 'cors';
import dotenv from 'dotenv';
import express from 'express';
import bodyParser from 'body-parser';
import { QsoData } from './types/QsoData';
import { XMLParser } from 'fast-xml-parser';
import { supabase } from './lib/supabaseClient';
import { LicenseData } from './types/LicenseData';

const app = express();
global.QRZ_KEY = "";
dotenv.config();

const corsOptions = {
origin: false,
optionsSuccessStatus: 200
}
app.use(express.json());
app.use(
cors({
origin: "*", // Set this to your actual front-end origin in production
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
credentials: true,
optionsSuccessStatus: 204,
allowedHeaders: "Content-Type,Authorization",
})
);
app.use(cors(corsOptions));

let req: Response;
async function start() {
Expand All @@ -39,11 +35,9 @@ app.get("/", (req, res) => {
res.send("Hello World");
});

app.get("/callsigns/:callsign", async (req, res) => {
const { data, error } = await supabase
.from("callsigns")
.select("*")
.eq("callsign", req.params.callsign);
app.get('/callsigns/:callsign', async (req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*')
const { data, error } = await supabase.from("callsigns").select('*').eq("callsign", req.params.callsign);
if (error) {
console.error(error);
res.status(500).send("Internal Server Error");
Expand Down Expand Up @@ -81,7 +75,8 @@ app.get("/callsigns/:callsign", async (req, res) => {
res.status(200).send(data[0]);
});

app.post("/qso/:callsign", async (req, res) => {
app.post('/qso/:callsign', async (req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*')
let json: QsoData = new QsoData();
json.band = req.body.band;
json.callsign = req.params.callsign;
Expand All @@ -98,11 +93,9 @@ app.post("/qso/:callsign", async (req, res) => {
res.sendStatus(200);
});

app.get("/qso/:callsign", async (req, res) => {
const { data, error } = await supabase
.from("qsoData")
.select("*")
.eq("operator", req.params.callsign);
app.get('/qso/:callsign', async (req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*')
const { data, error } = await supabase.from('qsoData').select('*').eq('operator', req.params.callsign);
if (error) {
console.error(error);
res.status(500).send(`Internal Server Error: ${error.message}`);
Expand Down

0 comments on commit b1a1f64

Please sign in to comment.