|
| 1 | +# Event-Driven Architecture Starter |
| 2 | + |
| 3 | +This is an event-driven microservices application using Pub/Sub for asynchronous communication between services. |
| 4 | + |
| 5 | +The example in this starter is an Uptime Monitoring System that continuously monitors the uptime of a list of websites. |
| 6 | + |
| 7 | +When it detects a website is down, it posts a Slack message notifying that the website is down, and another message when the website is back up again. |
| 8 | + |
| 9 | +It has a react frontend and you can try a demo version [here](https://uptime.encore.build/). |
| 10 | + |
| 11 | +[](https://app.encore.cloud/create-app/clone/ts-uptime) |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +## Build from scratch with a tutorial |
| 18 | + |
| 19 | +If you prefer, check out the [tutorial](https://encore.dev/docs/ts/tutorials/uptime) to learn how to build this application from scratch. |
| 20 | + |
| 21 | +## Prerequisites |
| 22 | + |
| 23 | +**Install Encore:** |
| 24 | +- **macOS:** `brew install encoredev/tap/encore` |
| 25 | +- **Linux:** `curl -L https://encore.dev/install.sh | bash` |
| 26 | +- **Windows:** `iwr https://encore.dev/install.ps1 | iex` |
| 27 | + |
| 28 | +**Docker:** |
| 29 | +1. Install [Docker](https://docker.com) |
| 30 | +2. Start Docker |
| 31 | + |
| 32 | +## Create app |
| 33 | + |
| 34 | +Create a local app from this template: |
| 35 | + |
| 36 | +```bash |
| 37 | +encore app create uptime-example --example=ts/uptime |
| 38 | +``` |
| 39 | + |
| 40 | +## Run app locally |
| 41 | + |
| 42 | +Before running your application, make sure you have Docker installed and running. Then run this command from your application's root folder: |
| 43 | + |
| 44 | +```bash |
| 45 | +encore run |
| 46 | +``` |
| 47 | + |
| 48 | +To use the Slack integration, set the Slack Webhook URL (see tutorial above): |
| 49 | +```bash |
| 50 | +encore secret set --type local,dev,pr,prod SlackWebhookURL |
| 51 | +``` |
| 52 | + |
| 53 | +**Note:** Cron Jobs do not execute when running locally. |
| 54 | + |
| 55 | +## View the frontend |
| 56 | + |
| 57 | +While `encore run` is running, head over to [http://localhost:4000/](http://localhost:4000/) to view the frontend for your uptime monitor. |
| 58 | + |
| 59 | +## Using the API |
| 60 | + |
| 61 | +Check if a given site is up (defaults to 'https://' if left out): |
| 62 | +```bash |
| 63 | +curl 'http://localhost:4000/ping/google.com' |
| 64 | +``` |
| 65 | + |
| 66 | +Add a site to be automatically pinged every 1 hour: |
| 67 | +```bash |
| 68 | +curl 'http://localhost:4000/site' -d '{"url":"google.com"}' |
| 69 | +``` |
| 70 | + |
| 71 | +Check all tracked sites immediately: |
| 72 | +```bash |
| 73 | +curl -X POST 'http://localhost:4000/check-all' |
| 74 | +``` |
| 75 | + |
| 76 | +Get the current status of all tracked sites: |
| 77 | +```bash |
| 78 | +curl 'http://localhost:4000/status' |
| 79 | +``` |
| 80 | + |
| 81 | +## Local Development Dashboard |
| 82 | + |
| 83 | +While `encore run` is running, open [http://localhost:9400/](http://localhost:9400/) to access Encore's [local developer dashboard](https://encore.dev/docs/ts/observability/dev-dash). |
| 84 | + |
| 85 | +Here you can see traces for all requests that you made while using the frontend, see your architecture diagram, and view API documentation in the Service Catalog. |
| 86 | + |
| 87 | +## Connecting to databases |
| 88 | + |
| 89 | +You can connect to your databases via psql shell: |
| 90 | + |
| 91 | +```bash |
| 92 | +encore db shell <database-name> --env=local --superuser |
| 93 | +``` |
| 94 | + |
| 95 | +Learn more in the [CLI docs](https://encore.dev/docs/ts/cli/cli-reference#database-management). |
| 96 | + |
| 97 | +## Deployment |
| 98 | + |
| 99 | +### Self-hosting |
| 100 | + |
| 101 | +See the [self-hosting instructions](https://encore.dev/docs/ts/self-host/build) for how to use `encore build docker` to create a Docker image and configure it. |
| 102 | + |
| 103 | +### Encore Cloud Platform |
| 104 | + |
| 105 | +Deploy your application to a free staging environment in Encore's development cloud using `git push encore`: |
| 106 | + |
| 107 | +```bash |
| 108 | +git add -A . |
| 109 | +git commit -m 'Commit message' |
| 110 | +git push encore |
| 111 | +``` |
| 112 | + |
| 113 | +You can also open your app in the [Cloud Dashboard](https://app.encore.dev) to integrate with GitHub, or connect your AWS/GCP account, enabling Encore to automatically handle cloud deployments for you. |
| 114 | + |
| 115 | +## Link to GitHub |
| 116 | + |
| 117 | +Follow these steps to link your app to GitHub: |
| 118 | + |
| 119 | +1. Create a GitHub repo, commit and push the app. |
| 120 | +2. Open your app in the [Cloud Dashboard](https://app.encore.dev). |
| 121 | +3. Go to **Settings ➔ GitHub** and click on **Link app to GitHub** to link your app to GitHub and select the repo you just created. |
| 122 | +4. 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**. |
| 123 | +5. Commit and push a change to GitHub to trigger a deploy. |
| 124 | + |
| 125 | +[Learn more in the docs](https://encore.dev/docs/platform/integrations/github) |
| 126 | + |
| 127 | +## Testing |
| 128 | + |
| 129 | +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](https://encore.dev/docs/ts/develop/testing) |
| 130 | + |
| 131 | +```bash |
| 132 | +encore test |
| 133 | +``` |
0 commit comments