serverless-http icon indicating copy to clipboard operation
serverless-http copied to clipboard

serverless-http 2.0.0 with express

Open olivierscheffler opened this issue 7 years ago • 55 comments

Hi !

We have a serverless application which use serverless-http 2.0.0 with express 4.16.4 and during a deploy, express seems not to recognise route.. We have make a rollback to 1.8.0 of serverless-http to make it works.. Do you have an idea why this could happen ?

Thx

olivierscheffler avatar Apr 22 '19 10:04 olivierscheffler

Crap sorry to hear that. Are you doing any other stuff in your handler or does it module.exports = serverless(app)?

dougmoscrop avatar Apr 22 '19 11:04 dougmoscrop

Hi ! Thx for the quick answer ! Yes we are doing that at the end of our file : module.exports.handler = serverless(app)

Should I remove that line or do something else ?

olivierscheffler avatar Apr 22 '19 11:04 olivierscheffler

nope that's still right, just making sure there was nothing else being done before/after -- I will have a look and see if I can reproduce

dougmoscrop avatar Apr 22 '19 11:04 dougmoscrop

This is the last line of my file.. And no changes have been made between 1.8.0 and 2.0.0 and it crashed..

Thx

olivierscheffler avatar Apr 22 '19 11:04 olivierscheffler

Can you try 2.0.1?

dougmoscrop avatar Apr 22 '19 12:04 dougmoscrop

I will try on the next day.. I will keep you update!

olivierscheffler avatar Apr 22 '19 12:04 olivierscheffler

Hi, I also have an issue with 2.0.1 & express 4.16.4 I upgraded from 1.8

Rolling back to 1.10.1 works for me

daniplaninc avatar Apr 23 '19 08:04 daniplaninc

Are you using a custom domain?

dougmoscrop avatar Apr 23 '19 12:04 dougmoscrop

Not for me... It's default domain by aws but in the future it could be possible

olivierscheffler avatar Apr 23 '19 12:04 olivierscheffler

I really want to get this fixed. Anything you can share would be helpful - error messages, logs, sample code..

I've updated the integration tests and they still pass, they could certainly use more test scenarios but I'm confused.

I've also deployed real prod software (using Koa) and it works. What express middleware are you using?

dougmoscrop avatar Apr 23 '19 20:04 dougmoscrop

Hi !

Here a sample of my code which i deploy simply on Lambda.

// Built-in
const { log } = console

// 3rd party lib
const serverless = require('serverless-http')
const bodyParser = require('body-parser')

const express = require('express')
const cors = require('cors')

const AWS = require('aws-sdk')
const { v4 } = require('uuid');


const app = express()

const { REPORT_TABLE } = process.env

const dynamoDb = new AWS.DynamoDB.DocumentClient()

app.use(cors())
app.use(bodyParser.json({strict: false}))

app.get('/', (req, res) => {
    res.send('Welcome')
})

// FIXME: For tree creation, validate existence of projectId and enterpriseId.
// FIXME: For enterpriseId we should use credential to infer correct enterpriseId.

// ------------------------------------------------------------------------------
// report (FIXME)
// ------------------------------------------------------------------------------

// FIXME: API call to Generate all monthly report Item

app.get('/report', (req, res) => { // Return back all monthly reports
    const TableName = REPORT_TABLE

    dynamoDb.scan(
        { TableName },
        (error, data) => {
            if (error) {
                log(error)
                res.status(400).json({error, message: `Can not list Report.`})
            } else {
                res.json(data.Items)
            }
        }
    )
})

module.exports.handler = serverless(app)

I didn't test on 2.0.1 but this code without change is not working on 2.0.0

Hope it helps you to find you..

I have no log to show you because nothing appear except a 404 error when I call an endpoint when I'm on AWS Lambda

olivierscheffler avatar Apr 23 '19 21:04 olivierscheffler

Yeah please try 2.0.1 it definitely fixed a routing bug.

@daniplaninc could you share more info about your errors?

dougmoscrop avatar Apr 23 '19 22:04 dougmoscrop

@dougmoscrop thx you for the update now it's working ! For me this issue can be close now !

olivierscheffler avatar Apr 23 '19 22:04 olivierscheffler

I am using Nuxt.js and there weren't any errors, just a timeout. I will take some time to try again this week to reproduce the issue and to see if I can get any more information out of it

daniplaninc avatar Apr 24 '19 07:04 daniplaninc

Thanks - is Nuxt.js something we should add tests for? Or is it just using another framework under the hood?

dougmoscrop avatar Apr 25 '19 19:04 dougmoscrop

I created a reproduction example for you. In this example I use serverless-offline but I tested with actual deployment to AWS and the result is identical. I don't know how to provide more debugging output, but if you need it and tell me how, I can do that.

To run the example you can either follow the steps outlined in STEPS.md STEPS.zip to recreate the whole thing or just download the zip file STEPS.zip (where i already did the steps) and run:

  1. npm i
  2. continue from step 7 in STEPS.md

As to whether you should have tests for Nuxt.js I really don't know. Probably not, since the link between Nuxt.js and serverless is express (in my case).

Nuxt.js is a SSR framework for Vue.js. I could not find any official examples for Nuxt.js + serverless, so I used some slightly outdated sources (https://github.com/jeehyukwon/nuxt-serverless, https://github.com/adnanrahic/serverless-side-rendering-vue-nuxt) to get started and modified/fixed the code accordingly.

daniplaninc avatar Apr 26 '19 08:04 daniplaninc

Thanks have reproduced and now get to go down the "how did this ever work" rabbit hole

dougmoscrop avatar Apr 26 '19 23:04 dougmoscrop

I created a reproduction example for you. In this example I use serverless-offline but I tested with actual deployment to AWS and the result is identical. I don't know how to provide more debugging output, but if you need it and tell me how, I can do that.

To run the example you can either follow the steps outlined in STEPS.md STEPS.zip to recreate the whole thing or just download the zip file STEPS.zip (where i already did the steps) and run:

  1. npm i
  2. continue from step 7 in STEPS.md

As to whether you should have tests for Nuxt.js I really don't know. Probably not, since the link between Nuxt.js and serverless is express (in my case).

Nuxt.js is a SSR framework for Vue.js. I could not find any official examples for Nuxt.js + serverless, so I used some slightly outdated sources (https://github.com/jeehyukwon/nuxt-serverless, https://github.com/adnanrahic/serverless-side-rendering-vue-nuxt) to get started and modified/fixed the code accordingly.

@daniplaninc I experienced the same issue with the same stack (Nuxtjs + Serverless + Lambda). I can't get it works after deploying to Lambda for almost two weeks. It is really frustrating...

smallcar88 avatar Apr 28 '19 16:04 smallcar88

@smallcar88 my workaround for now is downgrading to 1.10.1

daniplaninc avatar Apr 28 '19 19:04 daniplaninc

Based on my debugging I can't tell if I've reproduced the issue or just set nuxt up wrong. Can you just push a public repo that I can clone and npm install / npm start and then use my debugging stuff that way?

dougmoscrop avatar Apr 28 '19 21:04 dougmoscrop