/gugu-myopic-patients-community-backend

Eggjs based backend server for myopic patients community application.

Primary LanguageJavaScriptMIT LicenseMIT

Gugu logo

Gugu

The Eggjs+MongoDB+GraphQL based web server implementation for children myopia control community application.

related projects - WeChat Mini Program | CMS

‼️ This project is better to be used as sample code for learning purpose, instead of an application in production.

Gugu is released under the MIT license. Gugu is not under maintained anymore. Ask Me Anything.

Doc | 中文文档

Background

What's myopic control in children?

Myopia (or nearsightedness) is very common. One out of two people (50%) have it. With myopia, the eye is longer than normal from front to back, or the cornea (the clear window at the front of the eye) is too steeply curved. This makes things that are far away from you look blurry. Myopia is corrected with glasses, contact lenses or surgery in some cases. Having myopia can increase your chances of having some eye problems later, like cataract, glaucoma and retinal detachment.

Studies show myopia is becoming more common among children. While there is no proven direct link, research suggests that children who spend more time indoors doing near-focused activities (such as computer work, video games, and reading) have higher rates of myopia than those who spend more time outdoors.

Doctors are looking at ways to slow the progression of myopia in children. While myopia cannot be reversed, the goal of treatment is to keep it from getting worse. This can protect a child’s eye health in the future, despite still needing to wear glasses or contact lenses.[1]

[1]. Myopia Control in Children. (2020). Retrieved 28 May 2021, from https://www.aao.org/eye-health/treatments/myopia-control-in-children

Please refer to this for more information.

Tech stack

Installation

  1. install redis
    1. start redis - sudo systemctl start redis
  2. install elasticsearch RPM
    1. start elasticsearch - sudo systemctl start elasticsearch.service
    2. open http://localhost:9200/articles/_mapping?pretty=true
  3. install mongodb
    1. makir /data && mkdir /data/mongodb
    2. start mongodb deamon - mongod --auth --fork --dbpath /data/mongodb --logpath /var/log/mongodb/mongod.log
  4. install node
  5. install nginx(not necessary for local development)
    1. config nginx
    2. start nginx - nginx

Get start

Environment varibles

export JWT_SECRET_KEY='YOUR_JWT_SECRET_KEY' &&
export WECHAT_MINI_APP_ID='YOUR_WECHAT_NIMI_APP_ID' &&
export WECHAT_MINI_APP_SECRET='YOUR_WECHAT_MINI_APP_SECRET' &&
export MONGODB_URL='YOUR_MOGONDB_URL' &&
export ALIYUN_USER_BUCKET='YOUR_ALIYUN_USER_BUCKET' &&
export ALIYUN_BUCKET='YOUR_ALIYUN_BUCKET' &&
export ALIYUN_ACCESS_KEY_SECRET='YOUR_ALIYUN_ACCESS_KEY_SECRET' &&
export ALIYUN_ACCESS_KEY_ID='YOUR_ALIYUN_ACCESS_KEY_ID' && 
export ALIYUN_REGION='YOUR_ALIYUN_REGION'

Local development

Please get the permission to access the remote host first.

# Connect to the host by using SSH Tunnel to bridge the database port to your local.
ssh -L27018:localhost:27017 root@x.x.x.x
# Start the local server.
npm install 
npm run dev

open http://localhost:7001/graphql

Gamma environment deployment

npm run stop-gamma
npm install
npm run start-gamma

open http://localhost:7001/graphql

Prod environment deployment

npm run stop
npm install
npm run start

open http://localhost:7777/graphql

FAQ

1. how to use elasticvue to configure the elasticsearch?

Please add below configurations to the /etc/elasticsearch/elasticsearch.yml

# allow CORS requests from https://app.elasticvue.com
http.cors.enabled: true
http.cors.allow-origin: "https://app.elasticvue.com"

2. how to backup the database??

You could use mongoexport or any other GUI tools if you know.

export MONGODB_URL="MONGODB_URL"
mongoexport --uri=MONGODB_URL --collection=articles --out=articles.json

Or you could consider mongodump.

mongodump --uri=MONGODB_URL -o=gugudump

3. how to setup the auto database backup?

https://pranavprakash.net/2017/02/04/automate-mongodb-backups-using-cron-and-shell-script/

Please refer to the script in script/mongodb_dump.sh.

4. how to use the GUI tool to manage the ElasticSearch deployed in remote?

# use SSH Tunnel to bridge the port to your local.
ssh -L9201:localhost:9200 root@x.x.x.x`

Visit https://app.elasticvue.com/ and connect to localhost with port as 9201。

5. how to setup the MongoDB database?

  1. enable auth and create admin user
    1. mongo
    2. use admin
    3. db.createUser({ user: "opsAdmin", pwd: passwordPrompt(), roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]})
  2. create the new database
  3. create the admin roles for the new database

6. how to config Nginx?

server {
        listen 443;
        server_name YOUR_DOMAIN; # your domain
        # ssl config
        ssl on;
        ssl_certificate YOUR_CERTIFICATE_CERT; # your certificate's crt file name
        ssl_certificate_key YOUR_CERTIFICATE_KEY; # your certificate's key file name
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
        ssl_prefer_server_ciphers on;

        location / {
          proxy_pass http://127.0.0.1:7001;
        }
    }

7. project template

This repo is created from egg-graphql-boilerplate.

Discussions

Please open an issue for any questions,and I will respond as soon as possible。

Contributors

@zhangqi444, @happyerqi

📄 License

This project is MIT licensed.