Before start the server, you ought to set up environment variables as the following table.
Variable | Value |
---|---|
MONGO_URI | { Your Mongo URI, we recommend to use 'mlab' for free MongoDB server } |
REDIS_PORT | { Your Redis Port, we recommend to use 'RedisLabs' for free Redis service } |
REDIS_PWD | { Your Redis Password } |
REDIS_URI | { Your Redis URI } |
{ Email account that support SMTP protocol, for the usage of send validation email } | |
EMAIL_PWD | { Email password } |
Recommend REST API Testing Tools: Postman or Restlet.
Or use built-in tool: Swagger
Swagger API document: http://localhost:5000/swagger/
How to use Swagger UI: How to Use Swagger UI for API Testing
When access some private route, you may need to add JWT to header.
http://localhost:5000/api/users/register
After register a new user, the user have to activate his account via activation link in email. Or you can activate account thought the Api in the following.
http://localhost:5000/api/users/active/{activeToken}
Then you can login successfully.
http://localhost:5000/api/users/login
This project uses ESLint to detect suspicious code in JavaScript files. Visit http://eslint.org for details.
This project uses Jest and SuperTest for testing.
Visit https://jestjs.io/ and https://github.com/visionmedia/supertest for details.
To execute tests:
npm run test
The Book Recommendation Engine bases on k-nearest neighbors algorithm.
Basically it depends on the star of book review provided by other users.
Related Code can be referred to Lovely-AIP/server/recommendation/.
Related API document can be referred to http://localhost:5000/swagger/#/Recommendation.
You can test API by the following link:
http://localhost:5000/api/recommendation/book/5b5c0edc1e744f9760543a07
We implement some advance features base on Redis.
Related Code can be referred to Lovely-AIP/server/config/cache.js.
Redis Lab provides free Redis database with AWS region endpoint of 'ap-southeast-2', which is located in Sydney.
Provide ability to limit the rate of API request in a period of time.
In this project, APIs of 'Create User' and 'Send Validation Email' are under limitation of two requests each minute.
If reach the limitation, server will respond a status code of 429 which stands for 'Too Many Request'.
Related Code can be referred to Lovely-AIP/server/middlewares/rateLimit.js.
Set environment valuables inside of Dockerfile.
cd server/
docker build -t server .
docker run -p 5000:5000 -d --restart=always server