-
Notifications
You must be signed in to change notification settings - Fork 83
Open
Description
I am trying to implement serverless-mysql with my serverless-express app. I'm having issues initializing serverless-mysql and then passing that connection into the main handler so I can run queries in functions that are called by the router. I found this example online that runs a setup task for connecting to a db, but I'm concerned if I implement this with serverless-mysql it won't manage the connections properly.
// lambda.js
require('source-map-support/register')
const serverlessExpress = require('@vendia/serverless-express')
const app = require('./app')
let serverlessExpressInstance
function asyncTask () {
return new Promise((resolve) => {
setTimeout(() => resolve('connected to database'), 1000)
})
}
async function setup (event, context) {
const asyncValue = await asyncTask()
console.log(asyncValue)
serverlessExpressInstance = serverlessExpress({ app })
return serverlessExpressInstance(event, context)
}
function handler (event, context) {
if (serverlessExpressInstance) return serverlessExpressInstance(event, context)
return setup(event, context)
}
exports.handler = handler
Metadata
Metadata
Assignees
Labels
No labels