Bin
2025-12-16 971a2a12c03b74dd2d7d668b9dbc599f5131bcaf
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const sanityClient = require('@sanity/client');
 
const client = sanityClient({
  projectId: 'k7elabj6',
  dataset: 'production',
  apiVersion: '2021-03-25',
  token: process.env.SANITY_CREATE_TOKEN,
})
 
const handler = async (event) => {
 
  if (event.httpMethod !== "POST") {
    return { statusCode: 405, body: "Method Not Allowed" };
  }
 
  const headers = {
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Headers": "Content-Type",
    "Access-Control-Allow-Methods": "POST",
  };
 
  const {feedback, pageURL, helpful, pageTitle, submittedOn, email} = JSON.parse(event.body);
 
  const doc = {
    "_type": "docsFeedback",
    feedback,
    pageTitle,
    pageURL,
    submittedOn,
    helpful,
    email
  }
 
  console.log(doc);
  console.log(client);
 
  return client
    .create(doc)
    .then(res => {
      return {
        statusCode: 200,
        headers
      }
    })
    .catch(error => {
      console.log(error);
      return { statusCode: 500, body: error.toString() }
    })
}
 
module.exports = { handler }