- Nginx: the web server & RESTful API server powered by Openresty.
- MariaDB: the database server.
- db: contains the db-related files
- maria.tuned.cnf: tuned mariadb conf file
- ngx: contains the nginx-related files
- locs: contains the nginx locations conf files
- basic.cors.conf: CORS-related conf
- loc.rest.cors.conf: defines the RESTful apis
- lua: contains the lua scripts
- dbinfo.lua, database info
- handle_bulk_writes.lua, supports bulk operations
- handle_tables.lua, supports table level operations
- handle_tables_with_id.lua, supports single entry level operations
- handle_tables_with_ids.lua, supports multi entry level operations
- init.lua, the init script
- lbs.lua, the database wrapper
- nginx.conf: the nginx conf file
- userauth: the htpassword file for http basic authentication
- locs: contains the nginx locations conf files
- demo_site.sql: demo site table structure
- docker-compose.yml: docker compose file
- init.sh: setups the whole back-end environment
- rc.local: disables the transparent_hugepage
- server.tuning.sh: server performance tuning script
- OS: 64-bit ubuntu 14.04 / 16.04 server
- RAM: >= 8G
- Port: 443, 3306
sudo su
cd backend_deployment_demo
chmod +x init.sh
./init.sh
# (the init.sh will reboot the server)- Read operations:
- /{db}/{table}: get all records from a table
- verb: GET
- output: JSON
- /{db}/{table}/{id}: get one record specified by {id} from a table
- verb: GET
- output: JSON
- /{db}/{table}/{id},{id},..: get multi records specified by {id} from a table
- verb: GET
- output: JSON
- /{db}/{table}: get all records from a table
- Write operations:
- /_bulk/{db}/{table}
- verb:
- DELETE: bulk delete operations
- PUT: bulk upsert operations
- need http basic authentication
- input: JSON
- output: JSON
- verb:
- /_private/{db}/{table}
- verb:
- POST, create a new entry
- PUT, create a new entry if not exists, update otherwise
- need http basic authentication
- input: JSON
- output: JSON
- verb:
- /_private/{db}/{table}/{id}
- verb:
- PATCH, update the entry
- DELETE, delete the entry
- need http basic authentication
- input: JSON
- output: JSON
- verb:
- /_bulk/{db}/{table}
- As the nginx serves https, a self-signed cert will be generated by init.sh, one can specify a valid cert in the docker-compose.yml as needed, then run the following commands to active the cert:
cd backend_deployment_demo
sudo docker-compose restart backenddeploymentdemo_nginx_1- the init.sh will create a demo db called 'lbs_demo_site' with some default tables
- Default db root password is defined in docker-compose.yml
- DB naming convention for security: db name prefix with 'lbs_' will exposed to user, for example:
curl -k https://localhost/demo_site/imgs
# (the 'demo_site' will map to internal db 'lbs_demo_site')- All write operations need http basic authentication, one can edit the userauth file to add/remove users, an easy way to generate the password would be http://www.htaccesstools.com/htpasswd-generator/.
- One default user in the userauth: demoauthuser:20demoauthuser17
# (get all entries from lbs_demo_site.imgs)
curl -k https://localhost/demo_site/imgs
# (get one entry with id=3 from lbs_demo_site.imgs)
curl -k https://localhost/demo_site/imgs/3
# (get multi entries with ids=1,2,3,4 fromlbs_demo_site.imgs)
curl -k https://localhost/demo_site/imgs/1,2,3,4
# (insert one entry to lbs_demo_site.imgs, 'ZGVtb2F1dGh1c2VyOjIwZGVtb2F1dGh1c2VyMTc=' is base64 encoded version of 'demoauthuser:20demoauthuser17')
curl -kXPOST -H"Authorization: Basic ZGVtb2F1dGh1c2VyOjIwZGVtb2F1dGh1c2VyMTc=" https://localhost/_private/demo_site/imgs -d'{"type":"png", "imPath":"1.png"}'
# (update one entry with id=1 of lbs_demo_site.imgs)
curl -kXPATCH -H"Authorization: Basic ZGVtb2F1dGh1c2VyOjIwZGVtb2F1dGh1c2VyMTc=" https://localhost/_private/demo_site/imgs/1 -d'{"type":"png", "imPath":"1.1.png"}'
# (delete one enrty with id=1 of lbs_demo_site.imgs)
curl -kXDELETE -H"Authorization: Basic ZGVtb2F1dGh1c2VyOjIwZGVtb2F1dGh1c2VyMTc=" https://localhost/_private/demo_site/imgs/1
# (upsert multi entries with id=1,2 for lbs_demo_site.imgs)
curl -kXPUT -H"Authorization: Basic ZGVtb2F1dGh1c2VyOjIwZGVtb2F1dGh1c2VyMTc=" https://localhost/_bulk/demo_site/imgs -d'[{"_id":1, "type":"png", "imPath":"1.png"}, {"_id":2, "type":"png", "imPath":"2.png"}]'
# (delete multi entries with id=1,2 for lbs_demo_site.imgs)
curl -kXDELETE -H"Authorization: Basic ZGVtb2F1dGh1c2VyOjIwZGVtb2F1dGh1c2VyMTc=" https://localhost/_bulk/demo_site/imgs -d'[1, 2]'