Originally from: https://github.com/eficode/weatherapp
This simple weather application shows forecast of the current weather at user's location.
API Key from Open Weather Map is needed for the application to work.
Requirements: Compatible Docker Host, please see Docker documentation.
Run following command in terminal:
- Install Docker
- Install docker-compose
- Execute:
cd /path/to/this/repository
- For production:
APPID=API_KEY_HERE NODE_ENV=production docker-compose up --build backend frontend nginx
- For development:
APPID=API_KEY_HERE docker-compose up frontend backend
- There are environment variables available:
- These can be set by adding them in front the compose command and seperating them by space.
MAP_ENDPOINT
sets the base URL for Weather API endpoint. Optional.APPID
sets the Open Weather Map API Key. Mandatory.
- Wait a few minutes and please access the service with browser at:
- Production: http://localhost
- Development: http://localhost:8000
Requirements: Ansible, remote instance to run Ansible
Ansible is recommended when no ready host with docker and docker-compose exists. Currently it has only been tested on Ubuntu 22.04 LTS. It is only meant for production usage. Please run following commands in terminal:
- Get Ansible first
- Acquire eg. Amazon AWS EC2 Instance. Ubuntu LTS is a good choice.
- It should have TCP ports 80 and 9000 enabled. 1. In AWS this requires creating a new security group.
- Recommended way is to generate SSH Key Pair in PEM format and load it with eg with Bash:
*
eval $(ssh-agent) && ssh-add ssh-key-name-here.pem
- Create host configuration file eg.
weather.hosts
[weather] host1 ansible_host=AWS_INSTANCE_IP_HERE ansible_ssh_user=ubuntu
- Check host is reachable:
ansible -i weather.hosts host1 -m ping
- Run setup script:
ansible-playbook -i weather.hosts --extra-vars "APPID=API_KEY_HERE" --tags setup,start playbook.yml
- Wait a moment and please access the service with browser at:
http://AWS_INSTANCE_IP_HERE
- Run shutdown script:
ansible-playbook -i /usr/local/etc/ansible/hosts --tags stop playbook.yml
Requirements: npm
This is not recommended way but the application can be started locally via npm. Run following commands in terminal.
- Make sure you have npm
cd /path/to/this/repository
- Run:
APPID=API_KEY_HERE bash scripts/local.sh
- Please access the service with browser at: http://localhost:8000
The application demo is available at: http://13.51.48.14/
Requirements: Equal to section "Application Usage with Docker"
The application can be tested by following commands in terminal:
cd /path/to/this/repository
docker-compose up --build testing
- The command will run backend, frontend and integration tests.
The docker-compose file specifies several services:
- frontend: This handles development server and building for production.
- backend: This handles backend requests from frontend to Weather API servers.
- mockapi: This simulates Open Weather MAP API for testing.
- nginx: This provides production web server, and serves frontend assets.
- testing: This contains testing scripts to run unit and integration tests.
- The unit tests for Weather component don't test all cases which would happen for a real-world version.
- Integration tests to check that the container scripts, env. vars etc. do what they are supposed.
- The integration test files sometimes due to firefox crashing. In real-world app it would be investigated.
- There's not much verification of data from the backend opening door for XSS attacks.
- For Backend tests, fetch() was supposed to be mocked but apparently the common libs are not compatible.
- There is no access control for any of the backend services
- There hasn't been any performance testing or profiling for frontend or backend services.
- Not all browsers are tested.
- The application could be fuzzed by sending anomaly data via HTTP requests. This could reveal issues.
- The error message are not presented to the user when backend or API goes down.
- The repository could have CI features from eg. CircleCI which executes some automated tests or builds.
- There are some ESLint false positives, these have been marked.
- I would not use bash for anything more complex, and not copy-paste the script.
- There are no coverage maps or reports.
- Most browsers won't permi location sharing without HTTPS.
- The Mock API server has no tests other than the integration test.
- The Dockerfiles and entry files have a workaround for issue where npm doesn't install global packages correctly.
- Ports are static for now
- XZ or brotli compression for logs
- There could be NGINX reverse-proxy for more robust web server.
- Also HTTPS and certificates.
- Serve backend or frontend via regexp, or even vhost.
- Using memcached or redis for data storage would decrease request load.
- There would be room for improvement on layout/aesthetic side
- Graphs using some sort of JS library
- Colors for weather icons, and wind direction icons
- Bootstrap themes
- Animated backgrounds based on weather
- W3C HTML validator does not like the tags React produces even though it shouldn't use custom tags.
- It would be possible to do things like XHTML schema validation.
- Outdated, deprecated and unused packages could be automatically checked.
- Ideally the application would be available from docker registry or artifactory.
- There are possibility of updating-breaking changes because not all packages are downloaded with version freeze.
- Ideally there would be testing for different phones and eg. screenreaders.
- Ideally it would also be tested for accessibility for users with disabilities.
- Ideally ther woudl be compression and minimizatio
- fetch-mock uses deprecated library querystring
Ari Timonen