1

JAMStack People are using Netlify/Zeit (or AWS Lambda) functions to access their database. But there are cloud databases like Firestore which you can access securely and directly from your web/mobile apps as described here. Then why do not people embed the data access logic into their client app too? Why do they need extra layer of serverless functions?

sven anderson
  • 45
  • 1
  • 4

2 Answers2

1

for the example you mention you're completely right.

Serverless functions offer more opportunities though. Think for example of sending emails. Email providers usually don't provide a way to send emails from the client (rightfully so, I guess) and for that case, a serverless function can help.

Additionally not every data storage service provides a way to securely access/write data into a database right from the client. This would be another case where you could use a serverless function.

That said, serverless functions offer a fairly new way to quickly orchestrate and combine services to support and enrich your static site.

Hope that helps. :)

stefan judis
  • 3,416
  • 14
  • 22
1

You might use serverless functions in the case where you don't want to expose sensitive information, such as passwords, tokens, keys, to the end application. In this case, you make the function a middleman and inject this sensitive info, storing it safely on the server instead of in the user's client application (where they could hack into your sensitive data).

This is what process.env.VARIABLE is for in Nodejs for example.

DougA
  • 1,213
  • 9
  • 17