-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
31 lines (27 loc) · 855 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const serverless = require('serverless-http')
const express = require('express')
const { getAlbum } = require('./google-photos')
const app = express()
const allowedOrigins = ['http://localhost:8000', 'https://valentin-hervieu.fr']
app.use(function(req, res, next) {
const origin = req.headers.origin
if (allowedOrigins.includes(origin)) {
res.setHeader('Access-Control-Allow-Origin', origin)
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
next()
} else {
return res.status(403).json({
status: 403,
message: 'This API is only for https://valentin-hervieu.fr',
})
}
})
app.get('/', async (req, res) => {
try {
const results = await getAlbum(req.query.id)
res.json(results)
} catch (e) {
res.status(500)
}
})
module.exports.handler = serverless(app)