-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathget-preview.js
34 lines (31 loc) · 860 Bytes
/
get-preview.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
32
33
34
const fetch = require('node-fetch');
exports.handler = async function(event, context) {
const apiKey = process.env.TUGBOAT_API_KEY ?? 'none';
// Make sure a preview id is provided.
const body = JSON.parse(event.body);
if (!body.previewId) {
return {
statusCode: 404,
body: 'No preview ID provided.',
}
}
// Fetch preview info.
return fetch(`https://api.tugboatqa.com/v3/previews/${body.previewId}`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${apiKey}`,
},
})
.then(response => response.json())
.then(data => {
return {
statusCode: 202,
body: JSON.stringify(data),
}
}).catch(error => {
return {
statusCode: 400,
body: error.message,
};
});
}