|
1 |
| -# Deno starter API |
2 |
| - |
3 |
| -- Added PostgreSQL db driver with ORM => https://deno.land/x/[email protected] |
4 |
| -- validation to endpoints |
5 |
| -- import_maps |
6 |
| -- dockerized |
7 |
| - |
8 |
| - |
9 |
| -## Install |
10 |
| - |
11 |
| -Copy .env.example as .env in root directory. |
12 |
| - |
13 |
| -Run ``./scripts/build-docker-image-local.sh `` to build docker image. |
14 |
| - |
15 |
| - |
16 |
| -Run ``docker-compose up api`` to run Deno. |
17 |
| - |
18 |
| - |
19 |
| -Run ``docker-compose up watch`` to run Deno in watch mode. |
20 |
| - |
21 |
| - |
22 |
| -Tip: For Apple M1 users for Deno watch mode we need to change in Dockerfile: |
23 |
| - |
24 |
| -``FROM denoland/deno:1.15.3`` |
25 |
| - |
26 |
| -to this: |
27 |
| - |
28 |
| -``FROM lukechannings/deno:latest`` |
29 |
| - |
30 |
| - and to docker-compose ``platform: linux/amd64``: |
31 |
| - |
32 |
| -`` |
33 |
| -services: |
34 |
| - watch: |
35 |
| - image: api:local |
36 |
| - hostname: api |
37 |
| - platform: linux/amd64 |
38 |
| - volumes: |
39 |
| - ... |
40 |
| -`` |
41 |
| - |
42 |
| - |
43 |
| -## Migrations |
44 |
| - |
45 |
| -Migrations are in `` migrations `` folder. |
46 |
| - |
47 |
| -Syntax for class names is like in TypeORM: |
48 |
| - |
49 |
| -File `` 20220124110458-init.ts `` then class should be named `` Init20220124110458 `` : |
50 |
| -File `` 20220130024421-fixes_on_post_users.ts `` then class should be named `` Fixes_on_post_users20220130024421 `` : |
51 |
| - |
52 |
| -Files to migration folder we add manually. |
53 |
| - |
54 |
| -"down" method is not supported yet. |
55 |
| - |
56 |
| -Example migration file: |
57 |
| - |
58 |
| -`` |
59 |
| -import { Model } from "denodb"; |
60 |
| - |
61 |
| -export class Init20220124110458 { |
62 |
| - |
63 |
| - async up(client: any): Promise<void> { |
64 |
| - await client.queryObject(`SELECT * FROM "migrations"`); |
65 |
| - } |
66 |
| - |
67 |
| - async down(client: any): Promise<void> { |
68 |
| - await client.queryObject(`SELECT * FROM "migrations"`); |
69 |
| - } |
70 |
| -} |
71 |
| -`` |
| 1 | +**Deploy via github action** |
| 2 | +1. Go to https://deno.com/deploy and Sign up/in |
| 3 | +2. Select Github repository |
| 4 | +3. Add Github Account |
| 5 | +4. Choose single repo or all repos |
| 6 | +5. Click again on Select Github repository |
| 7 | +6. Your name or organization |
| 8 | +7. Choose repo |
| 9 | +8. Select Production branch |
| 10 | +9. Select `main.ts` file |
| 11 | +10. Change name but it need to be unique |
| 12 | +11. Link and after few sec we have working app which will update after push to repo |
| 13 | + |
| 14 | +**Deploying you project from local** |
| 15 | + |
| 16 | +1. Go to https://deno.com/deploy and Sign up/in |
| 17 | +2. Click on your profile picture then "Access Tokens" |
| 18 | +3. Create and copy access token |
| 19 | +4. Go back to projects and create new project |
| 20 | +5. Choose Empty Project |
| 21 | +6. Copy name of your project |
| 22 | +7. Use `deployctl deploy --project=PROJECT_NAME --token=TOKEN --import-map=import_map.json src/index.ts` |
| 23 | +8. Check returned url |
| 24 | +9. If every thing is correct then use same command but add `--prod` |
| 25 | +10. App is now deployed and eveyone can access it :D |
| 26 | + |
| 27 | + |
| 28 | +**Endpoints** |
| 29 | + |
| 30 | +GET /todos - list of all todos, |
| 31 | +POST /todo {text:'todo'} - create todo, |
| 32 | +PATCH /todo/:id - change todo's status |
0 commit comments