This is a serverless, NodeJS implementation of the Securelay API. It uses Redis as database. This particular implementation is configured to be hosted on Vercel out of the box. However, with a few variations, this implmentation may be run on any serverless platform such as AWS Lambda, provided a Redis DB, such as Upstash, can be used.
- Create a Vercel account.
- Get Redis in the form of Vercel's KV store and/or Upstash.
- Import this project and deploy it by following this tutorial.
- Note: Before deploying, set the environment variables through Vercel's Project Settings page by following the template provided in example.env.
- Create a Vercel account.
- Get Redis in the form of Vercel's KV store and/or Upstash.
- Set the environment variables through Vercel's Project Settings page by following the template provided in example.env.
- Get vercel CLI:
npm i -g vercel
. - Clone this repo:
git clone https://github.com/securelay/api-serverless-redis-vercel
. cd api-serverless-redis-vercel
.vercel login
.- Deploy locally and test:
vercel dev
. - If everything is working fine deploy publicly on Vercel:
vercel
.
This implementation, given its serverless nature, uses the REST API provided by Upstash for accessing Redis.
One database, provided directly by Upstash, is used for storing user data.
Another database, provided by Vercel's KV store, is used by the rate-limiter.
If you can manage a large enough Redis database, you can use it for both the above purposes, instead of using two different databases.
The dbKeyPrefix
, used in helper.js, would prevent key collisions.