Skip to content

Commit

Permalink
Merge pull request #25 from bcgov/FSADT1-287-api-gateway
Browse files Browse the repository at this point in the history
Merge: fix cors issue for api services portal
  • Loading branch information
MCatherine1994 authored Aug 17, 2022
2 parents 93df460 + 9c36c0f commit c8387ce
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
1 change: 1 addition & 0 deletions .github/gwa/apiService.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ services:
- /
methods:
- GET
- OPTIONS
strip_path: false
https_redirect_status_code: 426
path_handling: v0
Expand Down
18 changes: 18 additions & 0 deletions .github/gwa/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ services:
- /
methods:
- GET
- OPTIONS
strip_path: false
https_redirect_status_code: 426
path_handling: v0
Expand All @@ -31,3 +32,20 @@ services:
config:
hide_groups_header: true
allow: [E990939D]
- name: cors
tags: [ns.d2723f.test]
config:
origins: ["*"]
methods: [GET, POST, PUT, DELETE, PATCH]
headers:
[
Connection,
Upgrade,
Cache-Control,
Access-Control-Allow-Headers,
Access-Control-Request-Headers,
X-API-KEY,
Keep-Alive,
]
credentials: true
max_age: 3600
26 changes: 13 additions & 13 deletions backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ async function bootstrap() {
const app = await NestFactory.create(AppModule);

// enable cors only for our frontend/backend address
// const whitelist = [process.env.FRONTEND_URL, process.env.BACKEND_URL];
// app.enableCors({
// origin: (origin, callback) => {
// if (!origin || whitelist.indexOf(origin) !== -1) {
// callback(null, true);
// }
// // else {
// // callback(new Error('Not allowed by CORS'));
// // }
// },
// });

app.enableCors();
const whitelist = [process.env.FRONTEND_URL, process.env.BACKEND_URL];
app.enableCors({
origin: (origin, callback) => {
if (!origin || whitelist.indexOf(origin) !== -1) {
callback(null, true);
}
// else {
// callback(new Error('Not allowed by CORS'));
// }
},
});

// app.enableCors();

app.use(bodyParser.json({ limit: '100mb' }));

Expand Down

0 comments on commit c8387ce

Please sign in to comment.