Skip to content

Commit 7dba26d

Browse files
committed
add configuration labda function for netlify
1 parent cae139c commit 7dba26d

File tree

3 files changed

+45
-24
lines changed

3 files changed

+45
-24
lines changed

.netlify/functions/netlify-lambda.js

-23
This file was deleted.

functions/books.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const { default: axios } = require("axios")
2+
3+
exports.handler = async function(event, callback) {
4+
5+
const NYT_APP_API_KEY = process.env.REACT_APP_NYT_APP_API_KEY
6+
const BASE_URL = process.env.REACT_APP_BASE_URL_API_NYT
7+
8+
const API_URL = `${BASE_URL}/lists/overview.json?api-key=${NYT_APP_API_KEY}`
9+
10+
try {
11+
const response = await axios.get(API_URL);
12+
return {
13+
statusCode: 200,
14+
body: JSON.stringify(response.data)
15+
}
16+
} catch(error) {
17+
return {
18+
statusCode: 500,
19+
body: JSON.stringify(error)
20+
}
21+
}
22+
23+
// const pass = (body) => {callback(null, {statusCode: 200, body: JSON.stringify(body)})}
24+
25+
// const NYT_APP_API_KEY = process.env.REACT_APP_NYT_APP_API_KEY
26+
// const BASE_URL = process.env.REACT_APP_BASE_URL_API_NYT
27+
28+
// const API_URL = `${BASE_URL}/lists/overview.json?api-key=${NYT_APP_API_KEY}`
29+
// try {
30+
// let response = await fetch(API_URL,
31+
// {
32+
// method: event.httpMethod,
33+
// body: event.body
34+
// })
35+
// let data = await response.json()
36+
// await pass(data)
37+
// } catch(err) {
38+
// let error = {
39+
// statusCode: err.statusCode || 500,
40+
// body: JSON.stringify({error: err.message})
41+
// }
42+
// await pass(error)
43+
// }
44+
}

netlify.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[build]
22
Command = "npm run build"
3-
functions = "netlify-lambda"
3+
functions = "functions/"
44
Publish = "public"

0 commit comments

Comments
 (0)