I try to run the repository at https://github.com/elastic/search-ui/tree/master/examples/elasticsearch, which includes a Netlify function that proxies my Elasticsearch instance.
The function looks like:
/*
2 This is a Netlify Function that proxies our Elasticsearch instance.
3 */
4 import fetch from “node-fetch”;
5
6 exports.handler = function(event, context, callback) {
7 const host = process.env.ELASTICSEARCH_HOST;
8
9 fetch(${host}/national-parks/_search
, {
10 method: “POST”,
11 headers: { “content-type”: “application/json” },
12 body: event.body
13 })
14 .then(response => response.text().then(body => [response, body]))
15 .then(([response, body]) => {
16 callback(null, {
17 statusCode: response.status,
18 body: body
19 });
20 })
21 .catch(() => {
22 callback(null, {
23 statusCode: 500,
24 body: “An error occurred”
25 });
26 });
27 };
~
A netlify.toml file is also included,
1 [build]
2 functions = “netlify-lambda”
3 publish = “build/”
4 command = “npm run build”
I got error when I visit localhost:3000, which says:
http://localhost:3000/.netlify/functions/search 500 (Internal Server Error)
I did find some similar posts but not like my settings.
Can any one give a hint how to solve it?
Thank you.