Internal server error when deploying express using serverless


no others

**[Nothing like stupid or useless questions we all learn here]** I'm facing a problem that I really can't solve for days, I'm trying to use serverless to get my express app The program deploys to aws but when i try to access the endpoint i get this error

{"message": "Internal server error"}

I can't really figure out the problem also looked at other similar questions but nothing worked

Here is my serverless.yml

    service: my-express-application

provider:
  name: aws
  runtime: nodejs14.x
  stage: dev
  region: us-east-1

functions:
  app:
    handler: app.handler
    events:
      - http: ANY /
      - http: 'ANY /{proxy+}'

Here is my app.js

const express = require("express");
const cookieSession = require("cookie-session");
const passport = require("passport");
const serverless = require('serverless-http');
const authRoutes = require("./routes/auth");
const userRoute = require("./routes/user/postUser")
const planRoute =require("./routes/user/main")
const profileRoutes = require("./routes/profile");
const passportSetup = require("./config/passport-setup");
const mongoose = require("mongoose");
const keys = require("./config/keys");
const activitiesRoutes = require("./routes/activity");
const app = express();
const bodyParser = require("body-parser");
const router = express.Router();
const AWS = require("aws-sdk");
AWS.config.update({
    region: "us-east-1",
});
var docClient = new AWS.DynamoDB.DocumentClient();

// set view engine
app.set("view engine", "ejs");

// set up session cookies
app.use(
    cookieSession({
        maxAge: 24 * 60 * 60 * 1000,
        keys: [keys.session.cookieKey],
    })
);

// initialize passport
 app.use(passport.initialize());
 app.use(passport.session());

// connect to mongodb
mongoose.connect(keys.mongodb.dbURI, () => {
    console.log("connected to mongodb");
});

// set up routes
app.use("/plan",planRoute);
 app.use("/auth", authRoutes);
app.use("/auth", activitiesRoutes);
app.use("/profile", profileRoutes);
app.use("/uSer", userRoute);

//Here we are configuring express to use body-parser as middle-ware.
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

// create home route
app.get("/", (req, res) => {
    res.render("home", { user: req.user });
});
// app.get('/hi', function (req, res) {
//     res.send('Hello World!')
// })



app.listen(3000, () => {
    console.log("app now listening for requests on port 3000");
});
module.exports = serverless(app);
Tenet

One problem I see is that you are not exporting your method handlercorrectly . change this line

module.exports = serverless(app);

To this:

module.exports.handler = serverless(app);

(According to this .)

Related


Internal server error when deploying Arm template to Azure

ahaba I'm deploying a new metric alert to Azure using an ARM template. I'm following exactly the same way as the Microsoft doc . With the only change I'm deploying only one metric to one automation account instead of one storage account template file "variab

Internal server error when deploying Arm template to Azure

ahaba I'm deploying a new metric alert to Azure using an ARM template. I'm following exactly the same way as the Microsoft doc . With the only change I'm deploying only one metric to one automation account instead of one storage account template file "variab

Internal server error when using Flask session

Sedavid I want to use a Flask sessioncookie to save an ID between requests , but I get the result Internal Server Errorwhen I execute the request . I made a simple Flask app prototype to demonstrate my problem: #!/usr/bin/env python from flask import Flask, s

Internal server error when using retrofit

Syed Saad I am getting an internal server error when doing a PUT request using Retrofit on an Android app. this is my interface public interface RetrofitInterface { //for updating user @PUT("users/update/{email}") Call<Response> updateUser(@Path("email") Stri

Internal server error when using retrofit

Syed Saad I am getting an internal server error when doing a PUT request using Retrofit on an Android app. this is my interface public interface RetrofitInterface { //for updating user @PUT("users/update/{email}") Call<Response> updateUser(@Path("email") Stri

Internal server error when using retrofit

Syed Saad I am getting an internal server error when doing a PUT request using Retrofit on an Android app. this is my interface public interface RetrofitInterface { //for updating user @PUT("users/update/{email}") Call<Response> updateUser(@Path("email") Stri

Internal server error when using retrofit

Syed Saad I am getting an internal server error when doing a PUT request using Retrofit on an Android app. this is my interface public interface RetrofitInterface { //for updating user @PUT("users/update/{email}") Call<Response> updateUser(@Path("email") Stri

Internal server error when using retrofit

Syed Saad I am getting an internal server error when doing a PUT request using Retrofit on an Android app. this is my interface public interface RetrofitInterface { //for updating user @PUT("users/update/{email}") Call<Response> updateUser(@Path("email") Stri

Internal server error when using retrofit

Syed Saad I am getting an internal server error when doing a PUT request using Retrofit on an Android app. this is my interface public interface RetrofitInterface { //for updating user @PUT("users/update/{email}") Call<Response> updateUser(@Path("email") Stri

Internal server error when using retrofit

Syed Saad I am getting an internal server error when doing a PUT request using Retrofit on an Android app. this is my interface public interface RetrofitInterface { //for updating user @PUT("users/update/{email}") Call<Response> updateUser(@Path("email") Stri

Internal server error when using retrofit

Syed Saad I am getting an internal server error when doing a PUT request using Retrofit on an Android app. this is my interface public interface RetrofitInterface { //for updating user @PUT("users/update/{email}") Call<Response> updateUser(@Path("email") Stri

Internal server error when using retrofit

Syed Saad I am getting an internal server error when doing a PUT request using Retrofit on an Android app. this is my interface public interface RetrofitInterface { //for updating user @PUT("users/update/{email}") Call<Response> updateUser(@Path("email") Stri

Internal server error when using retrofit

Syed Saad I am getting an internal server error when doing a PUT request using Retrofit on an Android app. this is my interface public interface RetrofitInterface { //for updating user @PUT("users/update/{email}") Call<Response> updateUser(@Path("email") Stri

Internal server error when using retrofit

Syed Saad I am getting an internal server error when doing a PUT request using Retrofit on an Android app. this is my interface public interface RetrofitInterface { //for updating user @PUT("users/update/{email}") Call<Response> updateUser(@Path("email") Stri

Internal server error when using retrofit

Syed Saad I am getting an internal server error when doing a PUT request using Retrofit on an Android app. this is my interface public interface RetrofitInterface { //for updating user @PUT("users/update/{email}") Call<Response> updateUser(@Path("email") Stri

Internal server error when using retrofit

Syed Saad I am getting an internal server error when doing a PUT request using Retrofit on an Android app. this is my interface public interface RetrofitInterface { //for updating user @PUT("users/update/{email}") Call<Response> updateUser(@Path("email") Stri