├── supabase ├── seed.sql ├── functions │ └── api │ │ └── index.ts └── config.toml ├── .github └── workflows │ └── deploy.yml └── README.md /supabase/seed.sql: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /supabase/functions/api/index.ts: -------------------------------------------------------------------------------- 1 | import { Application, Router } from 'https://deno.land/x/oak@v12.6.1/mod.ts' 2 | 3 | const router = new Router(); 4 | 5 | router 6 | .get("/api", (context) => { 7 | context.response.body = "This is an example GET endpoint"; 8 | }) 9 | .post("/api", (context) => { 10 | context.response.body = "This is an example POST endpoint"; 11 | }); 12 | 13 | const app = new Application() 14 | 15 | app.use(router.routes()) 16 | app.use(router.allowedMethods()) 17 | 18 | await app.listen({ port: 54321 })`` 19 | -------------------------------------------------------------------------------- /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | name: Deploy 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | workflow_dispatch: 8 | 9 | jobs: 10 | deploy: 11 | runs-on: ubuntu-latest 12 | env: 13 | SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }} 14 | SUPABASE_DB_PASSWORD: ${{secrets.SUPABASE_DB_PASSWORD}} 15 | PROJECT_ID: ${{secrets.STAGING_PROJECT_ID}} 16 | steps: 17 | - uses: actions/checkout@v3 18 | - uses: supabase/setup-cli@v1 19 | with: 20 | version: latest 21 | - name: Run Database Migrations 22 | run: | 23 | supabase link --project-ref $PROJECT_ID 24 | supabase db push 25 | - name: Deploy 26 | run: supabase functions deploy --project-ref $PROJECT_ID --debug 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Supabase REST API Starter Kit 2 | This project will help you create a full REST API using Supabase Edge Functions. 3 | 4 | # What is included inside? 5 | 6 | - Skeleton for building a REST API with Deno Oak 7 | - CI/CD template, which handles deployment and database migrations 8 | 9 | # How to setup: 10 | 11 | You can setup this API in 4 steps: 12 | 13 | 1. Fork this repository 14 | 15 | 2. Create a Supabase project if you don't have one 16 | 17 | 3. Add secrets: 18 | 19 | In order for this API to be deployed automatically we need to set these secrets in our repository: 20 | ``` 21 | SUPABASE_ACCESS_TOKEN 22 | SUPABASE_DB_PASSWORD 23 | SUPABASE_PROJECT_ID 24 | ``` 25 | 4. Trigger the deployment workflow 26 | 27 | # Feedback 28 | Found a bug or have a suggestion? Please contact me on X [@rokasdam](https://twitter.com/rokasdam). 29 | -------------------------------------------------------------------------------- /supabase/config.toml: -------------------------------------------------------------------------------- 1 | # A string used to distinguish different Supabase projects on the same host. Defaults to the 2 | # working directory name when running `supabase init`. 3 | project_id = "ChopVid.API" 4 | 5 | [api] 6 | enabled = true 7 | # Port to use for the API URL. 8 | port = 54321 9 | # Schemas to expose in your API. Tables, views and stored procedures in this schema will get API 10 | # endpoints. public and storage are always included. 11 | schemas = ["public", "storage", "graphql_public"] 12 | # Extra schemas to add to the search_path of every request. public is always included. 13 | extra_search_path = ["public", "extensions"] 14 | # The maximum number of rows returns from a view, table, or stored procedure. Limits payload size 15 | # for accidental or malicious requests. 16 | max_rows = 1000 17 | 18 | [db] 19 | # Port to use for the local database URL. 20 | port = 54322 21 | # Port used by db diff command to initialize the shadow database. 22 | shadow_port = 54320 23 | # The database major version to use. This has to be the same as your remote database's. Run `SHOW 24 | # server_version;` on the remote database to check. 25 | major_version = 15 26 | 27 | [db.pooler] 28 | enabled = false 29 | # Port to use for the local connection pooler. 30 | port = 54329 31 | # Specifies when a server connection can be reused by other clients. 32 | # Configure one of the supported pooler modes: `transaction`, `session`. 33 | pool_mode = "transaction" 34 | # How many server connections to allow per user/database pair. 35 | default_pool_size = 20 36 | # Maximum number of client connections allowed. 37 | max_client_conn = 100 38 | 39 | [realtime] 40 | enabled = true 41 | # Bind realtime via either IPv4 or IPv6. (default: IPv6) 42 | # ip_version = "IPv6" 43 | 44 | [studio] 45 | enabled = true 46 | # Port to use for Supabase Studio. 47 | port = 54323 48 | # External URL of the API server that frontend connects to. 49 | api_url = "http://127.0.0.1" 50 | 51 | # Email testing server. Emails sent with the local dev setup are not actually sent - rather, they 52 | # are monitored, and you can view the emails that would have been sent from the web interface. 53 | [inbucket] 54 | enabled = true 55 | # Port to use for the email testing server web interface. 56 | port = 54324 57 | # Uncomment to expose additional ports for testing user applications that send emails. 58 | # smtp_port = 54325 59 | # pop3_port = 54326 60 | 61 | [storage] 62 | enabled = true 63 | # The maximum file size allowed (e.g. "5MB", "500KB"). 64 | file_size_limit = "50MiB" 65 | 66 | [auth] 67 | enabled = true 68 | # The base URL of your website. Used as an allow-list for redirects and for constructing URLs used 69 | # in emails. 70 | site_url = "http://127.0.0.1:3000" 71 | # A list of *exact* URLs that auth providers are permitted to redirect to post authentication. 72 | additional_redirect_urls = ["https://127.0.0.1:3000"] 73 | # How long tokens are valid for, in seconds. Defaults to 3600 (1 hour), maximum 604,800 (1 week). 74 | jwt_expiry = 3600 75 | # If disabled, the refresh token will never expire. 76 | enable_refresh_token_rotation = true 77 | # Allows refresh tokens to be reused after expiry, up to the specified interval in seconds. 78 | # Requires enable_refresh_token_rotation = true. 79 | refresh_token_reuse_interval = 10 80 | # Allow/disallow new user signups to your project. 81 | enable_signup = true 82 | 83 | [auth.email] 84 | # Allow/disallow new user signups via email to your project. 85 | enable_signup = true 86 | # If enabled, a user will be required to confirm any email change on both the old, and new email 87 | # addresses. If disabled, only the new email is required to confirm. 88 | double_confirm_changes = true 89 | # If enabled, users need to confirm their email address before signing in. 90 | enable_confirmations = false 91 | 92 | # Uncomment to customize email template 93 | # [auth.email.template.invite] 94 | # subject = "You have been invited" 95 | # content_path = "./supabase/templates/invite.html" 96 | 97 | [auth.sms] 98 | # Allow/disallow new user signups via SMS to your project. 99 | enable_signup = true 100 | # If enabled, users need to confirm their phone number before signing in. 101 | enable_confirmations = false 102 | # Template for sending OTP to users 103 | template = "Your code is {{ .Code }} ." 104 | 105 | # Use pre-defined map of phone number to OTP for testing. 106 | [auth.sms.test_otp] 107 | # 4152127777 = "123456" 108 | 109 | # Configure one of the supported SMS providers: `twilio`, `twilio_verify`, `messagebird`, `textlocal`, `vonage`. 110 | [auth.sms.twilio] 111 | enabled = false 112 | account_sid = "" 113 | message_service_sid = "" 114 | # DO NOT commit your Twilio auth token to git. Use environment variable substitution instead: 115 | auth_token = "env(SUPABASE_AUTH_SMS_TWILIO_AUTH_TOKEN)" 116 | 117 | # Use an external OAuth provider. The full list of providers are: `apple`, `azure`, `bitbucket`, 118 | # `discord`, `facebook`, `github`, `gitlab`, `google`, `keycloak`, `linkedin`, `notion`, `twitch`, 119 | # `twitter`, `slack`, `spotify`, `workos`, `zoom`. 120 | [auth.external.apple] 121 | enabled = false 122 | client_id = "" 123 | # DO NOT commit your OAuth provider secret to git. Use environment variable substitution instead: 124 | secret = "env(SUPABASE_AUTH_EXTERNAL_APPLE_SECRET)" 125 | # Overrides the default auth redirectUrl. 126 | redirect_uri = "" 127 | # Overrides the default auth provider URL. Used to support self-hosted gitlab, single-tenant Azure, 128 | # or any other third-party OIDC providers. 129 | url = "" 130 | 131 | [analytics] 132 | enabled = false 133 | port = 54327 134 | vector_port = 54328 135 | # Configure one of the supported backends: `postgres`, `bigquery`. 136 | backend = "postgres" 137 | 138 | # Experimental features may be deprecated any time 139 | [experimental] 140 | # Configures Postgres storage engine to use OrioleDB (S3) 141 | orioledb_version = "" 142 | --------------------------------------------------------------------------------