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

Add a context #197

Open
tcarac opened this issue Oct 16, 2021 · 2 comments
Open

Add a context #197

tcarac opened this issue Oct 16, 2021 · 2 comments

Comments

@tcarac
Copy link

tcarac commented Oct 16, 2021

Hey, im loving lambda-api so far.
Quick question, is there a way to add a context to handlers ?
Let's say

app.get("/posts", getPosts);
async function getPosts(req,res,context){
const prisma = context.prisma;
return prisma.posts.findMany({});
}

And this is basically for code splitting

@warapitiya
Copy link

You can use req.context to retrieve the context object.

@GuidoNebiolo
Copy link

Hi @tcarac
you can do this assigning the service you want directly to app during initialization.

example:
const api = require('lambda-api')()
api.services = {prisma}
api.post('/', async (req, res) => { const prisma = api.services.prisma; return prisma.posts.findMany({});}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants