👽 API
This commit is contained in:
21
functions/api.js
Normal file
21
functions/api.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
// Docs on event and context https://www.netlify.com/docs/functions/#the-handler-method
|
||||||
|
exports.handler = async (event, context) => {
|
||||||
|
switch (event.httpMethod) {
|
||||||
|
case "GET":
|
||||||
|
try {
|
||||||
|
const name = event.queryStringParameters.name || "World"
|
||||||
|
return {
|
||||||
|
statusCode: 200,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ message: `Hello ${name}` }),
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
return { statusCode: 500, body: err.toString() }
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return { statusCode: 405, body: "Method Not Allowed" }
|
||||||
|
}
|
||||||
|
}
|
||||||
3
netlify.toml
Normal file
3
netlify.toml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[build]
|
||||||
|
command = "npm run generate"
|
||||||
|
functions = "functions/"
|
||||||
Reference in New Issue
Block a user