A swift vapor back-end to run your own Roadmap server and database. The database uses postgreSQL.
To run your own back-end there is 2 solutions:
- Use a free Remote server & database
- Use your server
This method has the advantage of being free and accessible for the roadmap usage.
- Koyeb account to expose the API.
- ElephantSQL account for the database.
It is pretty straightforward. Create your account with a Tiny Turtle
plan, and you are ready.
Koyeb offers the possibility to deploy an API easily. Once you have your account and started to create your instance, this is the configuration you could use to run a healthy service:
- Choose deployment using a Github repository.
- Add the github project link (I recommend you to fork the repository as koyeb will deploy each time there is a commit).
- Choose the Dockerfile builder.
- Override the entrypoint :
["./App"]
- Override the command:
serve
- Override the arguments
["--env","production","--hostname","0.0.0.0","--port","8080"]
- Choose the Web Service type.
- Choose the region you want.
- Choose the instance (nano instance should be sufficient for this API)
- Next add the following environment variables so your API knows how to connect to the database:
Variable Name | Type | Value |
---|---|---|
DATABASE_HOST | PlainText | db_server |
DATABASE_USERNAME | PlainText | db_username |
DATABASE_PASSWORD | PlainText | db_password |
APP_PORT | PlainText | 8080 |
Note
You can find and manage that informations in your elephantSQL account console.
- Expose the
8080
port with theHTTP
protocol and/
for the Path. - Put a scaling number of one (it should be plenty for our usage).
- Docker to deploy the API and the database.
If you have your own server already, you can put a .env
file at the root of this repository with the following values:
DATABASE_HOST=[db_host]
DATABASE_USERNAME=[db_username]
DATABASE_PASSWORD=[password]
APP_PORT=8080
Those values depend on how you want to configure your database. See a simple and complete example here 👇
DATABASE_HOST=db
DATABASE_USERNAME=vapor_username
DATABASE_PASSWORD=vapor_password
APP_PORT=8080
When you have the .env
file set up, you can run this command at the repository root to build and run the API and the database:
docker-compose up --build
Next you should expose the API port and you are ready.
You can take inspiration from the gist from Tyler Stillwater that already shows how to use a custom API.
https://[YOUR_APP].koyeb.app/get/{namespace}/{featureId}
to get the feature count.
https://[YOUR_APP].koyeb.app/add/{namespace}/{featureId}/{delta}
to increment or decrement the feature count.
Thanks for Antoine, Jordi and Hidde van der Ploeg to have developed a valuable Swift Package like Roadmap.
Also thanks for Tyler Stillwater for integrating the possibility to use a custom API and inspire me to develop this project.