Example Web Application
This is an example web application written using JS with a Python backend and MongoDB data store. It finds the user's location or sets a default, then requests fake places or generates 10 new ones with fake reviews (up to 5). The user can leave reviews or get directions for a selected place. Generated data and saved reviews last for 10 minutes from creation. If places and reviews get deleted, refresh browser.
- Install MongoDB
OS X:
brew install mongodb
mkdir -p data/db
- Run MongoDB
mongod --fork --dbpath 'data/db' --bind_ip 127.0.0.1 --logpath '/usr/local/var/log/mongodb/mongo.log' --logappend --pidfilepath db.pid
- Install dependencies
pip install -r requirements.txt
mkdir logs
touch logs/app.log
- Get a Map Access Token
The example application uses Mapbox.
Either in an .env
file enter:
MAP_ACCESS_TOKEN='{INSERT_YOUR_TOKEN}'
or
In the config.py file replace {INSERT_YOUR_TOKEN}
- Run Server Flask
FLASK_DEBUG=true FLASK_APP=app/main.py flask run
or
Gunicorn
gunicorn main:app --error-logfile logs/error.log --access-logfile logs/access.log --pid app.pid --daemon --chdir app && tail -f logs/app.log
- Launch Browser
Either 127.0.0.1:5000 or 127.0.0.1:8000
- Stop Services
Flask Ctrl+C
or
Gunicorn
kill -s HUP $(cat app.pid) && kill -9 $(cat app.pid)
MongoDB
mongo --eval "db.getSiblingDB('admin').shutdownServer()"
- MongoDB
- Python (dotenv, Flask, Jinja, PyMongo, Faker)
- jQuery
- Leaflet
- Bootstrap
- Feather Icons
- Spin Kit
- Sanitize input when leaving a review. As of now XSS is possible.
- Dependency injection for backend code to clean up global variables.
- Extract JS template strings to script tags with 'type="text/x-template"' to separate presentation and functionality.