Skip to content

Commit a029d7e

Browse files
committed
configure cors
1 parent 5400bda commit a029d7e

File tree

3 files changed

+58
-25
lines changed

3 files changed

+58
-25
lines changed

apps/api/package-lock.json

Lines changed: 41 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@supabase/supabase-js": "^2.45.4",
2222
"airtable": "^0.12.2",
2323
"body-parser": "^1.20.3",
24+
"cors": "^2.8.5",
2425
"dotenv": "^16.4.5",
2526
"express": "^4.21.0",
2627
"swagger-jsdoc": "^6.2.8",

apps/api/server.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,27 @@ const bodyParser = require('body-parser');
1010
const auth = require('./auth');
1111
const things = require('./apps/catalog/routes/things');
1212
const lending = require('./apps/librarian');
13+
const cors = require('cors');
1314
const apiKeyMiddleware = require('./middleware/apiKey');
1415

16+
const corsOptions = Object.freeze({
17+
allowedHeaders: [
18+
'Origin',
19+
'x-api-key',
20+
'X-Requested-With',
21+
'Content-Type',
22+
'Accept',
23+
'supabase-access-token',
24+
'supabase-refresh-token'
25+
],
26+
credentials: true,
27+
origin: process.env.ACCESS_CONTROL_ALLOW_ORIGIN
28+
});
29+
30+
app.use(cors(corsOptions));
1531
app.use(apiKeyMiddleware);
1632
app.use(bodyParser.json());
1733

18-
app.all('*', (req, res, next) => {
19-
res.header("Access-Control-Allow-Origin", "*");
20-
res.header("Access-Control-Allow-Headers", "Origin, x-api-key, X-Requested-With, Content-Type, Accept, supabase-access-token, supabase-refresh-token");
21-
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD");
22-
res.header("Access-Control-Allow-Credentials", "true");
23-
res.header("Access-Control-Allow-Private-Network", "true");
24-
next();
25-
});
26-
2734
app.get('/', (_, res) => {
2835
res.send('You have reached the Things API');
2936
});

0 commit comments

Comments
 (0)