Cors Issue 'no http status ok' when using mongoose

Hello dear netlify community,

when I make a lambda function connection and connect my application to mongoose, I get the error

Here is my toml file


force = true
headers = {X-From = “Netlify”}


Define which paths this specific [[headers]] block will cover.

for = “/"
Access-Control-Allow-Origin = "

Here is the request:

const mongoose = require(‘mongoose’)
const User = require(‘…/server/models/user’)

await mongoose.connect(${process.env.MONGO_URI}, {
useNewUrlParser: true,
useUnifiedTopology: true

exports.handler = async (event, context, callback) => {
context.callbackWaitsForEmptyEventLoop = false;

  const user =  await User.findOne({
    email: 'bbbb'
  if(!user) {
    await User.create({
      name: 'kkk',
      email: 'llll',
      verified: true,
return {
  statusCode: 200,
  headers: {
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Methods": "DELETE, POST, GET, OPTIONS",
    "Access-Control-Allow-Headers": "X-Token, append,delete,entries,foreach,get,has,keys,set,values,Authorization",

} catch (err) {
return {
statusCode: 500,
body: JSON.stringify({ msg: err.message })

In the frontend, I invoke the function like so:

async function loginUser(e) {
const response = await fetch(${process.env.REACT_APP_NETLIFY_URL}.netlify/functions/addtask, {
method: ‘POST’,
mode: ‘cors’,
statusCode: 200,
headers: {
‘Content-Type’: ‘application/json’,
‘Accept’: ‘application/json’,
“Access-Control-Allow-Origin”: “*”,
“Access-Control-Allow-Methods”: “DELETE, POST, GET, OPTIONS”,
“Access-Control-Allow-Headers”: “Origin, X-Token, append,delete,entries,foreach,get,has,keys,set,values,Authorization”,
body: JSON.stringify({
} catch (err){
console.log(err, ‘err here’)

Here is my github repo and here the deployed app https://master– Thanks so much for helping me and everyone with this problem out!

Hey @SomeSome,

Sorry for the delay. This thread got missed due to some problem with our issue tracking system.

Are you still experiencing issues?