Skip to content

Commit

Permalink
added cors headers
Browse files Browse the repository at this point in the history
  • Loading branch information
bgv2 authored Oct 1, 2024
1 parent 62aa49e commit e5d3eaa
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ const rateLimitConfig = {
legacyHeaders: false,
}
app.use(rateLimit(rateLimitConfig))

app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*")
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
next()
})
app.get('/randquote', async function (_req, res) {
const { quote, source: author } = await dbGet('SELECT quote, source FROM Quotes WHERE id IN (SELECT id FROM Quotes ORDER BY RANDOM() LIMIT 1);')
res.json({ quote, author })
Expand Down Expand Up @@ -54,4 +58,4 @@ app.get('/', function (_req, res) {
const port = 3000
app.listen(port, "", () => { console.log('App listening at http://localhost:' + port) })

export default app
export default app

0 comments on commit e5d3eaa

Please sign in to comment.