This is an Encore starter for a URL Shortener. It has two API endpoints and a PostgreSQL database to store the URL IDs and retrieve the full URL given an ID.
If you prefer to built it yourself, check out the tutorial to learn how to build this application from scratch.
Install Encore:
- macOS:
brew install encoredev/tap/encore
- Linux:
curl -L https://encore.dev/install.sh | bash
- Windows:
iwr https://encore.dev/install.ps1 | iex
Docker:
- Install Docker
- Start Docker
Create a local app from this template:
encore app create my-app-name --example=ts/url-shortener
Before running your application, make sure you have Docker installed and running. Then run this command from your application's root folder:
encore run
curl 'http://127.0.0.1:4000/url' -d '{"url":"https://google.com"}'
curl 'http://127.0.0.1:4000/url/:id'
curl 'http://127.0.0.1:4000/url'
While encore run
is running, open http://localhost:9400 to access Encore's local developer dashboard.
Here you can see API docs, make requests in the API explorer, and view traces of the responses.
To see that your app is running, you can ping the API to shorten a url.
curl 'http://localhost:4000/url' -d '{"url":"https://news.ycombinator.com"}'
When you ping the API, you will see traces and logs appearing in the local development dashboard: http://localhost:9400
You can connect to your databases via psql shell:
encore db shell <database-name> --env=local --superuser
Learn more in the CLI docs.
See the self-hosting instructions for how to use encore build docker
to create a Docker image and configure it.
Deploy your application to a free staging environment in Encore's development cloud using git push encore
:
git add -A .
git commit -m 'Commit message'
git push encore
You can also open your app in the Cloud Dashboard to integrate with GitHub, or connect your AWS/GCP account, enabling Encore to automatically handle cloud deployments for you.
Follow these steps to link your app to GitHub:
- Create a GitHub repo, commit and push the app.
- Open your app in the Cloud Dashboard.
- Go to Settings ➔ GitHub and click on Link app to GitHub to link your app to GitHub and select the repo you just created.
- To configure Encore to automatically trigger deploys when you push to a specific branch name, go to the Overview page for your intended environment. Click on Settings and then in the section Branch Push configure the Branch name and hit Save.
- Commit and push a change to GitHub to trigger a deploy.
To run tests, configure the test
command in your package.json
to the test runner of your choice, and then use the command encore test
from the CLI. The encore test
command sets up all the necessary infrastructure in test mode before handing over to the test runner. Learn more
encore test