-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'localsupabase' into deployed
- Loading branch information
Showing
19 changed files
with
499 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,51 @@ | ||
# NisaInvest-TFB-BE | ||
|
||
There are a few important considerations and modifications we need to make to ensure it works well with Vercel's serverless environment. Here's what you need to know: | ||
This backend project is designed to work with Vercel's serverless environment. Here's a quick guide to get you started: | ||
|
||
Vercel and Express: | ||
* Vercel primarily supports serverless functions, which means we need to adapt our Express app to work in this environment. | ||
* File Structure: We'll need to modify our file structure slightly to work with Vercel's conventions. | ||
* Serverless Function: We'll create a serverless function that wraps our Express app. | ||
## Deployment | ||
|
||
NISAINVEST-TFB-BE/ | ||
├── api/ | ||
│ └── index.ts | ||
├── src/ | ||
│ ├── app.ts //Here we set the express server and its middleware | ||
│ └── (other source files) | ||
├── package.json | ||
├── tsconfig.json | ||
└── vercel.json | ||
### Vercel Setup | ||
- Adapt the Express app for serverless functions | ||
- Modify file structure to match Vercel's conventions | ||
- Create a serverless function wrapping the Express app | ||
|
||
### Environment Variables | ||
- **Development**: Use `.env` file | ||
CORS_ORIGIN=http://localhost:3000 | ||
- **Production**: Set in Vercel dashboard | ||
CORS_ORIGIN=https://your-frontend-domain.com | ||
|
||
Vercel (Production): | ||
On Vercel, you'll set environment variables through their dashboard or CLI. These will be available in your code via process.env without needing to use dotenv. | ||
### Deployment Command | ||
```npx vercel --prod``` | ||
Backend URL: https://nisa-invest-tfb-be.vercel.app/ | ||
|
||
In your .env file for development: | ||
```CopyCORS_ORIGIN=http://localhost:3000``` | ||
### Local Development | ||
#### Supabase Commands | ||
##### Start local instance: | ||
```npx supabase start``` | ||
##### Stop local instance: | ||
```npx supabase stop``` | ||
##### Reset local DB: | ||
```npx supabase db reset``` | ||
##### Access local Supabase Studio: | ||
```http://localhost:54323/project/default``` | ||
|
||
In Vercel's dashboard or CLI, set the same variable: | ||
```CopyCORS_ORIGIN=https://your-frontend-domain.com``` | ||
### Supabase Remote Setup | ||
|
||
Production Environment (Vercel): | ||
Vercel automatically sets NODE_ENV to production in its deployment environment. You don't need to set this manually. | ||
1) Generate access token at https://app.supabase.com | ||
2) Set environment variable: | ||
```export SUPABASE_ACCESS_TOKEN=your_new_token_here``` | ||
|
||
To redeploy: | ||
npx vercel --prod | ||
3) Link with remote DB: | ||
```npx supabase link --project-ref xzzacivebczssoporkmz``` | ||
|
||
|
||
### Reset Remote DB (Caution: Will reseed) | ||
```npx supabase db reset --linked``` | ||
|
||
### Best Practices | ||
|
||
* Keep environment variables secure | ||
* Test thoroughly before deploying | ||
* Monitor logs in Vercel dashboard for issues | ||
|
||
The backend will be accessible on: | ||
https://nisa-invest-tfb-be.vercel.app/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
user_id,goal_id,assigned_at,due_date,status,completed_at | ||
1,26,2023-07-01T10:00:00Z,2023-12-31T23:59:59Z,in_progress, | ||
1,30,2023-07-02T11:30:00Z,2023-11-30T23:59:59Z,completed,2023-10-15T14:45:00Z | ||
1,35,2023-07-03T09:15:00Z,2024-01-31T23:59:59Z,not_done, | ||
1,41,2023-07-04T14:00:00Z,2023-12-15T23:59:59Z,in_progress, | ||
1,45,2023-07-05T16:45:00Z,2024-02-29T23:59:59Z,not_done, | ||
2,28,2023-07-06T08:30:00Z,2023-10-31T23:59:59Z,completed,2023-09-30T18:20:00Z | ||
2,33,2023-07-07T13:00:00Z,2024-03-31T23:59:59Z,in_progress, | ||
2,38,2023-07-08T11:45:00Z,2023-12-31T23:59:59Z,not_done, | ||
2,43,2023-07-09T10:30:00Z,2024-01-15T23:59:59Z,in_progress, | ||
3,25,2023-07-10T15:15:00Z,2023-11-30T23:59:59Z,completed,2023-11-15T09:30:00Z | ||
3,31,2023-07-11T09:45:00Z,2024-02-28T23:59:59Z,in_progress, | ||
3,37,2023-07-12T14:30:00Z,2023-12-31T23:59:59Z,not_done, | ||
4,24,2023-07-13T11:00:00Z,2023-10-31T23:59:59Z,completed,2023-10-20T16:45:00Z | ||
4,29,2023-07-14T16:30:00Z,2024-01-31T23:59:59Z,in_progress, | ||
5,27,2023-07-15T10:45:00Z,2023-12-15T23:59:59Z,not_done, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import { createClient } from '@supabase/supabase-js' | ||
import dotenv from 'dotenv' | ||
import config from './config/config' | ||
|
||
dotenv.config() | ||
console.log('NODE_ENV:', config.nodeEnv) | ||
console.log('Supabase URL:', config.supabaseUrl) | ||
console.log('Supabase Key:', config.supabaseAnonKey ? '**hidden**' : 'undefined') | ||
|
||
const supabaseUrl = process.env.SUPABASE_URL! | ||
const supabaseAnonKey = process.env.SUPABASE_ANON_KEY! | ||
|
||
if (!supabaseUrl || !supabaseAnonKey) { | ||
throw new Error('Supabase URL and Anon Key are required') | ||
if (!config.supabaseUrl || !config.supabaseAnonKey) { | ||
throw new Error('Supabase URL or Key is missing. Check your environment variables.') | ||
} | ||
|
||
export const supabase = createClient(supabaseUrl, supabaseAnonKey) | ||
const supabase = createClient(config.supabaseUrl, config.supabaseAnonKey) | ||
|
||
export default supabase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Supabase | ||
.branches | ||
.temp | ||
.env |
Oops, something went wrong.