Skip to content

Redirect service allows the configuration of “domain pools” which define the target domains to redirect to, and weight associated with each domain.

License

Notifications You must be signed in to change notification settings

edisnake/redirect-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redirect Domain Service

Redirect service allows the configuration of “domain pools” which define the target domains to redirect to, and weight associated with each domain.

The redirect endpoint (http://localhost:8006//v1/redirect_domain/{pool_id}) chooses a random domain of the given pool based on its weight and forces an HTTP redirect to it; Configuration can be done by using the service OpenAPI page. Any custom UI is out of scope.

Tech Stack

  • Docker
  • FastAPI
  • MySQL
  • SQLAlchemy

Setup development environment (Docker compose)

Please install Docker and Docker compose first.

Manual setup

After installation, run the following command to create a local Docker container.

docker-compose up --build

If Docker is running successfully, the API and DB server will be launched as shown in the following:

Be careful, it won't work if the port is occupied by another application.

Setup with the VS Code Dev Containers extension

The above setup can be used for development, but you can also setup dev env with using the VS Code Dev Containers extension.

  • Install VS code and the Dev Containers extension.
  • Run the Dev Containers: Open Folder in Container... command from the Command Palette or quick actions Status bar item, and select the project folder.
  • Wait until the building of the application is finished, then access the application url

Note

How to enable Python code formatter (black) and linter (flake8) with VSCode extension

If you're VS Code user, you can easily setup Python code formatter (black) and linter (flake8) by simply installing the extensions.

Automatic formatting settings have already been defined .vscode/settings.json.

Just install following:

If you are using the Dev Container, this configuration is already done in the Dev Container settings, so you can skip it.

How to check the DB tables in the container

Use following command to go inside of docker container:

docker-compose exec redirect_db sh

Then use mysql command to execute a query:

mysql -u appuser -p
mysql> USE redirect_app;
mysql> SHOW TABLES;
mysql> SELECT * FROM user;

Your initial MySQL password is defined in mysql/local.env.

To reinitialize the DB, remove the named volumes declared in the "volumes" section of the Compose file.

https://docs.docker.com/engine/reference/commandline/compose_down/

docker-compose down -v

How to add a library

Python libraries used in this app are defined in api/requirements.txt.

Also you may want to add libraries such as requests, in which case follow these steps:

  • Add the library to requirements.txt

e.g., if you want to add requests:

requests==2.32.3

Then try a re-build and see.

docker-compose down; docker-compose build; docker-compose up;

Environment variable

Some environment variables, like a database name and user are defined in docker-compose.yml or Dockerfile.

Then, run docker-compose up to launch the development environment.
And confirm that your DB changes are reflected.

How to use the App

services

About

Redirect service allows the configuration of “domain pools” which define the target domains to redirect to, and weight associated with each domain.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published