简体   繁体   English

使用无服务器部署 express 时出现内部服务器错误

[英]internal server error with when deploying express with serverless

im facing a problem that i really couldn't resolve for days, I am trying to deploy my express app to AWS using serverless, but when I try to access the endpoint I receive this error我遇到了几天都无法解决的问题,我正在尝试使用无服务器将我的 Express 应用程序部署到 AWS,但是当我尝试访问端点时,我收到此错误

{"message": "Internal server error"} {“消息”:“内部服务器错误”}

i really can't figure out the problem also viewed the other similar questions but nothing works我真的无法弄清楚问题也查看了其他类似的问题,但没有任何效果

here is my serverless.yml这是我的 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+}'

and this is my app.js这是我的 app.js

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.listen(3000, () => {
    console.log("app now listening for requests on port 3000");
});
module.exports = serverless(app);

One problem I see it that you are not exporting your handler method correctly.我发现一个问题是您没有正确导出handler方法。 Change this line改变这一行

module.exports = serverless(app);

to this:对此:

module.exports.handler = serverless(app);

(Per this .) (根据这个。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用无服务器组件部署 Express 应用程序时如何停止“缺少 CORS 允许来源错误”? - How to stop 'CORS missing allow origin error' when deploying Express application using Serverless Component? 错误消息:使用无服务器将 nodejs api 部署到 awsapigateway 后出现内部服务器错误 - Error message: Internal server error after nodejs api deploy using serverless to awsapigateway AWS http api 网关 + lambda (node/express) 内部服务器错误 - AWS http api gateway + lambda (node/express) Internal Server Error Express Amplify Serverless/GraphQL 与 Express 服务器端后端 - Express Amplify Serverless/GraphQL vs Express Server-Side backend 使用无服务器框架将 Python package 部署到 AWS lambda 时出错 - Error deploying Python package to AWS lambda using Serverless framework “errorMessage”:在 AWS 无服务器上部署时“server.app.use 不是一个函数” - "errorMessage": "server.app.use is not a function" while deploying on AWS serverless 消息:尝试访问 AWS 网关 api 时出现“内部服务器错误” - message: "Internal server error" when try to access aws gateway api 当我尝试更新 dynamodb 时出现内部服务器错误 - Internal Server Error when i try to update dynamodb 使用 Python 在 Lambda 中查询 DynamoDB 时出现“内部服务器错误” - "Internal Server Error" when querying of DynamoDB in Lambda using Python 无服务器图像处理程序请求大文件大小时出现 502 错误 - 502 error when Serverless image handler requests a large file size
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM