Skip to content

nginx and Sanic server, with Postgres backend

License

Notifications You must be signed in to change notification settings

nutratech/server

Repository files navigation

server

linux-python status: unknown Coverage status deploy-dev status: unknown deploy-prod status: unknown Code style: black License: GPL-3

Current URL: https://nutra.tk/api/

See database: https://github.com/nutratech/db

See cli: https://github.com/nutratech/cli

Dependencies

You will need to install the following, or newer.

  • Python 3.8 (with venv support)
  • PostgreSQL 12 (with dev library, see db for details)

Initialize Database

You can install PostgreSQL, register it as a startup service, and populate data.

You can also set the PSQL_* vars in .env and point to a remote database instance.

See db/README.rst.

Initialize Server

Initialize with this.

It will require python-venv and (optionally) direnv.

make init
make deps

Run

make run

NOTE: You can also debug from VSCode, or PyCharm.

Format, Lint, and Test

The code is formatted with black, autopep8, and isort. The code is also linted with a variety of tools, see the Makefile

The code is tested with pytest and coverage. The unit tests require a Postgres connection. They use the recommended practices for testing a Sanic app.

NOTE: It's recommended to run this before committing changes.

make format lint test

Config Variables in .env file

The server runs with default configuration locally.

Check the .env.local file for specifics on deployed environments.

These can be supplied as environment variables to the systemctl service. See ntserv.service for an example.