InstaShare API
Distributed under the terms of the MIT license.
This project was built using:
- Python
- Django
- Django Rest Framework
- Docker
- Poetry (not required)
(This step is not required if you use poetry)
python -m venv .venv
pip install .
or use poetry:
poetry install
source .venv/bin/activate
or use poetry:
poetry shell
Then run the development server
python manage.py runserver
This project uses Docker for deployment
You must create .env file with the next variables:
DJANGO_SETTINGS_MODULE
: project settings. (setconfig.settings.develop
).SECRET_KEY
: used to provide cryptographic signing.DB_HOST
: postgres database host.DB_PORT
: postgres database port.DB_USER
: postgres database user.POSTGRES_PASSWORD
: postgres database password.POSTGRES_DB
: postgres database name.ALLOWED_HOSTS
: A list of strings representing the host/domain names that this Django site can serve.REDIS_URL
: The redis url. (Ex: redis://localhost:6379)
Here you have an example
You must have installed Docker and Docker Compose to run the application:
docker-compose up -d
Here set an example for a nginx configuration and with the certbot to manage the ssl. This project is set to only run in secure protocol (https)
server {
server_name instashare-api.ragnarok22.dev;
location / {
proxy_pass http://localhost:8000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/instashare-api.ragnarok22.dev/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/instashare-api.ragnarok22.dev/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = instashare-api.ragnarok22.dev) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name instashare-api.ragnarok22.dev;
return 404; # managed by Certbot
}
For running test
coverage run manage.py test apps
coverage report
Run the project:
python manage.py runserver
And then go to http://localhost:8000/docs/