dherault / dherault/serverless-offline

DataCloneError

Open
#1,637 9 comments 3 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
5.3k
Forks
811
Avg merge
2d 4h
Merged PRs (30d)
3

Description

## Bug Report

**Current Behavior**

I started the API gateway locally through the command "serverless offline". It exposed all the endpoints when I hit them. I got the following error :
Error:
DataCloneError: async (event_, context = {}) => {
const event = cleanUpEvent(event_, options);

**Sample Code**

- file: serverless.yml

```yaml
service: recipe
frameworkVersion: '3'

provider:
name: aws
runtime: nodejs14.x
iam:
role:
statements:
- Effect: 'Allow'
Action:
- "lambda:InvokeFunction"
- "lambda:InvokeAsync"
Resource: "*"

functions:
main:
handler: main.handler
name: main
events:
- http:
path: /healthCheck
method: get
- http:
path: /setWebhook
method: get
- http:
path: /botMessage
method: post
getAPIResultStoreInDatabase:
handler: fetch-api-response.handler
name: getAPIResultStoreInDatabase

plugins:
- serverless-offline
```

- file: handler.js

``exports.handler = async () => {
const token = await fetchBotToken();
const url = #url
// const localUrl = 'https://cfba-2a02-6b61-8173-0-f462-a49f-4fd8-313b.eu.ngrok.io/botMessage'
const app = express();

// parse the updates to JSON
app.use(express.json());

app.get('/healthCheck', (req, res) => {
res.status(200).send('API Gateway URL is working!!!')
})

app.get('/setWebhook', async (req, res) => {

const options = {
method: 'GET',
url: `https://api.telegram.org/bot${token}/setWebhook?url=${url}`,
};
const apiResponse = await axios.request(options)
const result = apiResponse ?.data
return res.status(200).json(result)

})

// We are receiving updates at the route below!
app.post(`/botMessage`, async (req, res) => {

const responseArray = await responseHandler(req.body.message.text)
const promiseResponse = await Promise.all(responseArray.map((response) => {
const options = {
method: 'POST',
url: `https://api.telegram.org/bot${token}/sendMessage`,
data: {
"chat_id": req.body.message.chat.id,
"text": response,
"parse_mode": "HTML"
}
};
return axios.request(options)
}))

return res.status(200).json(promiseResponse.map((response) => {
return {
status: response.status,
text: response.data.result.text
}
}))
});

return serverless(app);

}
```

**Expected behavior/code**

The expected behavior is that it will expose all the endpoints and I can hit on them and they will work.

**Environment**
- "serverless-http": "^2.7.0"
- "serverless-offline": "^12.0.3"
- `node.js` version: [e.g. v16.13.0]
- `OS`: Windows 10

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.