Skip to content
This repository has been archived by the owner on Dec 24, 2022. It is now read-only.

Latest commit

 

History

History

server

Server

Set Up Environment Variable

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 { Email account that support SMTP protocol, for the usage of send validation email }
EMAIL_PWD { Email password }

API

Recommend REST API Testing Tools: Postman or Restlet.

Or use built-in tool: Swagger

Using 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.

Register

http://localhost:5000/api/users/register register

Confirm account

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} Activate Account

Then you can login successfully.

Login

http://localhost:5000/api/users/login login

Development

This project uses ESLint to detect suspicious code in JavaScript files. Visit http://eslint.org for details.

Testing

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

Book Recommendation

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

Redis

We implement some advance features base on Redis.

Related Code can be referred to Lovely-AIP/server/config/cache.js.

Caching Data

Redis Lab provides free Redis database with AWS region endpoint of 'ap-southeast-2', which is located in Sydney.

Rate Limit

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.

Docker

Set environment valuables inside of Dockerfile.

Build

cd server/
docker build -t server .

Run

docker run -p 5000:5000 -d --restart=always server