Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to upgrade to 4.x ? #360

Closed
j0k3r opened this issue Feb 1, 2021 · 11 comments
Closed

How to upgrade to 4.x ? #360

j0k3r opened this issue Feb 1, 2021 · 11 comments
Labels

Comments

@j0k3r
Copy link

j0k3r commented Feb 1, 2021

As the 4.x is a major release and no UPGRADE.md file exist in the repo, I was wondering how should we upgrade from the 3.4.0 version ?

@brettstack
Copy link
Collaborator

@brettstack
Copy link
Collaborator

Let me know if you have encounter any issues :)

@j0k3r
Copy link
Author

j0k3r commented Feb 2, 2021

Great, thanks!
We were using that method to speedup warm function:

import serverlessExpress from '@vendia/serverless-express'
import app from 'src/app'
import configureApp from 'src/configureApp'

// global variable server to keep hot in lambda
// server is set at the first call and reused then
let server

export default async (event, context) => {
  if (server) {
    return serverlessExpress.proxy(server, event, context, 'PROMISE').promise
  }

  console.log('Server does not exist')

  try {
    // init dbs connexion, middleware and other stuff
    await configureApp(app)
  } catch (e) {
    console.error(e)
  }

  // other initialization

  server = serverlessExpress.createServer(app)

  return serverlessExpress.proxy(server, event, context, 'PROMISE').promise
}

It looks like it's a bit more complicated now that we can't init the server and pass event & context later?

@brettstack
Copy link
Collaborator

You should be able to do something like this #351 (comment)

@j0k3r
Copy link
Author

j0k3r commented Feb 2, 2021

It worked. Thanks

I used:

import serverlessExpress from '@vendia/serverless-express'
import app from 'src/app'
import configureApp from 'src/configureApp'

// global variable server to keep hot in lambda
// server is set at the first call and reused then
let server

export default async (event, context) => {
  if (server) {
    return server(event, context)
  }

  console.log('Server does not exist')

  try {
    // init dbs connexion, middleware and other stuff
    await configureApp(app)
  } catch (e) {
    console.error(e)
  }

  // other initialization

  server = serverlessExpress({ app }).handler

  return server(event, context)
}

An other question we do have a lot of debug message now which are quite huge (it killed a chrome tab just to try to view it on Cloudwatch):
image

How can we disable them?

@brettstack
Copy link
Collaborator

Ahh good point. Originally this was using Winston and would only log when NODE_ENV === 'development'. I'll get a fix out, but you do also have the option of providing your own log object https://github.com/vendia/serverless-express#log

@brettstack
Copy link
Collaborator

I've pushed a patch that at least doesn't log debug for production builds. Will get something better in soon to allow setting log.level without needing to specify the other log methods

github-actions bot pushed a commit that referenced this issue Feb 8, 2021
# [4.2.0](v4.1.3...v4.2.0) (2021-02-08)

### Features

* add logSettings to override log level and default log level to error ([a0e8bdb](a0e8bdb)), closes [#360](#360)
@github-actions
Copy link

github-actions bot commented Feb 8, 2021

🎉 This issue has been resolved in version 4.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@j0k3r
Copy link
Author

j0k3r commented Feb 23, 2021

Thanks, finally used that snippet and it worked as expected!

import serverlessExpress from '@vendia/serverless-express'
import app from 'src/app'
import configureApp from 'src/configureApp'

// global variable server to keep hot in lambda
// server is set at the first call and reused then
let server

export default async (event, context) => {
  if (server) {
    return server(event, context)
  }

  console.log('Server does not exist')

  try {
    // init dbs connexion, middleware and other stuff
    await configureApp(app)
  } catch (e) {
    console.error(e)
  }

  // other initialization

  server = serverlessExpress({ app })

  return server(event, context)
}

@sudhirjena
Copy link

@j0k3r - Could you please share the a code snippet for configureApp. I am also running into a similar issue but unsure what your configureApp does?

@j0k3r
Copy link
Author

j0k3r commented Aug 30, 2021

@sudhirjena Here is a short version:

import app from './app'

app.set('isProduction', process.env.NODE_ENV === 'prod')
app.set('json spaces', 2)

export default (application) => {
  application.set('app:ready', true)

  return application
}

And app.js:

import express from 'express'

process.env.TZ = 'Europe/Paris'

export default express()

OneDev0411 added a commit to OneDev0411/serverless-express that referenced this issue Mar 16, 2023
# [4.2.0](CodeGenieApp/serverless-express@v4.1.3...v4.2.0) (2021-02-08)

### Features

* add logSettings to override log level and default log level to error ([a0e8bdb](CodeGenieApp/serverless-express@a0e8bdb)), closes [#360](CodeGenieApp/serverless-express#360)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants