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

update allow origin header #3551

Open
wants to merge 2 commits into
base: integration
Choose a base branch
from
Open
Show file tree
Hide file tree
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
16 changes: 15 additions & 1 deletion packages/api/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,19 @@ const rejectBodyInGetAndDelete = (req, res, next) => {
next();
};

const getAllowedOrigin = () => {
switch (environment) {
case 'development':
return 'http://localhost:3000';
case 'integration':
return 'https://beta.litefarm.org';
case 'production':
return 'https://app.litefarm.org';
default:
return 'https://app.litefarm.org';
}
};

app
.use(applyExpressJSON)
.use(express.urlencoded({ extended: true }))
Expand All @@ -261,7 +274,8 @@ app
// prevent CORS errors
.use(cors())
.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
const origin = getAllowedOrigin();
res.header('Access-Control-Allow-Origin', origin);
res.header(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept, Authorization',
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ http {

proxy_set_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
proxy_pass_request_headers on;
proxy_set_header 'Access-Control-Allow-Origin' '*';
proxy_set_header 'Access-Control-Allow-Origin' 'https://beta.litefarm.org';
proxy_pass http://backend:5000/;
}
listen 443 ssl; # managed by Certbot
Expand Down
Loading