Skip to content

Commit 67c110a

Browse files
authored
add code from middleware demo (#187)
1 parent 78d148e commit 67c110a

File tree

10 files changed

+1884
-0
lines changed

10 files changed

+1884
-0
lines changed

ts/middleware-demo/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Middleware Demo
2+
3+
This is the code example used in the middleware demo [stream](https://www.youtube.com/watch?v=qInxenZVDJs). It demonstrates how to implement a simple authorization middleware that only allows users to update themselves while still being able to view other users in the system.
4+
5+
All endpoints require authentication, pass the string `userid:1` in the authorization header to login as user with id 1. Replace 1 with any number.
6+
7+
**Endpoints:**
8+
9+
- `/users` (POST) - Create a new user
10+
- `/users` (GET) - List all users
11+
- `/users/:id` (GET) - Get user by id
12+
- `/users/:id` (PUT) - Update user by id
13+
- `/users/:id` (DELETE) - delete user by id
14+
15+
16+
## Developing locally
17+
18+
### Prerequisite: Installing Encore
19+
20+
If this is the first time you're using Encore, you first need to install the CLI that runs the local development
21+
environment. Use the appropriate command for your system:
22+
23+
- **macOS:** `brew install encoredev/tap/encore`
24+
- **Linux:** `curl -L https://encore.dev/install.sh | bash`
25+
- **Windows:** `iwr https://encore.dev/install.ps1 | iex`
26+
27+
When you have installed Encore, run:
28+
29+
```bash
30+
encore app create --example=ts/middleware-demo
31+
```
32+
33+
## Running locally
34+
35+
Before running your application, make sure you have Docker installed and running. It's required to locally run Encore applications with databases.
36+
37+
```bash
38+
encore run
39+
```
40+
41+
Go to [http://localhost:4000](http://localhost:4000) in the browser to see the example frontend.
42+
43+
You can also access Encore's [local developer dashboard](https://encore.dev/docs/observability/dev-dash) on <http://localhost:9400/> to view traces, API documentation, and more.
44+
45+
## Deployment
46+
47+
Deploy your application to a staging environment in Encore's free development cloud:
48+
49+
```bash
50+
git add -A .
51+
git commit -m 'Commit message'
52+
git push encore
53+
```
54+
55+
Then head over to the [Cloud Dashboard](https://app.encore.dev) to monitor your deployment and find your production URL.
56+
57+
From there you can also connect your own AWS or GCP account to use for deployment.
58+
59+
Now off you go into the clouds!
60+
61+
## Testing
62+
63+
```bash
64+
encore test
65+
```
66+

ts/middleware-demo/encore.app

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"id": "",
3+
"lang": "typescript"
4+
}

0 commit comments

Comments
 (0)