Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated header options #62

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions apps/api/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,27 @@ import cors from 'cors';
import * as dotenv from 'dotenv';
dotenv.config();

// function transformCorsOrg() {
// const result = [];
// const corsOrgEnv = process.env.CORS_URLS || '';
// const corsOrg = corsOrgEnv.split(',') ;
// console.log(corsOrg);
// return corsOrg
// }

class App {
public app: Application;
public port: number;
private corsOptions;

constructor(authControllers, controllers) {
this.corsOptions = process.env.CORS_URLS || '';
// #TODO | figure out how to turn env var string to an array of strings
this.corsOptions = [
"https://vercel.com/jazicorn/recodecamp-web",
"https://recodecamp-web.vercel.app",
"https://www.recodecamp.com"
];
console.log(this.corsOptions)
this.app = express();
this.port = parseInt(process.env.PORT as string) || 8000;
this.initMiddlewares();
Expand All @@ -35,7 +49,7 @@ class App {
res.sendStatus(204);
});
this.app.use(cors({
origin: this.corsOptions.replace(/['"`]/g, '');
origin: this.corsOptions
}));
// this.app.use( "/", (req, res, next) => {
// res.setHeader('access-control-allow-origin', '*');
Expand Down