From 8bd6c7bf3c5d85e2aca5b1c355f494fc057193bd Mon Sep 17 00:00:00 2001 From: bogdanripa Date: Sun, 1 Sep 2024 15:01:10 +0300 Subject: [PATCH 1/3] Updated the refine example to use postgres and auth via IAC --- docs/frameworks/refine.md | 46 +++++---------------------------------- 1 file changed, 6 insertions(+), 40 deletions(-) diff --git a/docs/frameworks/refine.md b/docs/frameworks/refine.md index 2419767..258b72d 100644 --- a/docs/frameworks/refine.md +++ b/docs/frameworks/refine.md @@ -15,7 +15,7 @@ import TabItem from '@theme/TabItem'; . :::tip -Get started in no time with the [Refine template](https://app.genez.io/start/deploy?repository=https://github.com/Genez-io/refine-genezio&base_path=example-json). +Get started in no time with the [Refine template](https://app.genez.io/start/deploy?repository=https://github.com/Genez-io/refine-genezio&base_path=example-postgres). ::: # Deployment @@ -70,7 +70,7 @@ Go to https://github.com/Genez-io/refine-genezio/fork and fork the repo ```bash git clone YOUR_REPO_URL -cd refine-genezio/example-json +cd refine-genezio/example-postgres ```

3. Run the refine App locally

@@ -106,52 +106,18 @@ $ App Dashboard URL: https://app.genez.io/project// $ Frontend URL: https://.app.genez.io ``` -## Set-up the app -## 1. Setup Genezio's Authentication on this project - -You don't want anyone to be able to access your APIs and make updates to the contents, so we will set-up Genezio's authentication feature on this project. - -First you need to go to the **App Dashboard URL** that was listed in the output of the `genezio deploy` command. - -On the app dashboard page, click "Authentication" on the left-side menu to enable the auth feature on this project. You might need to create a database in the process, but this should be quite straight-forward. - -Next, enable the Email provider from the list of providers. - -On the same page you will find a **Token** and a **Region**. Open the `/client/src/authProvider.ts` file and update the **authToken** variable with the **Token** on this page. - -## 2. Update the reset password URL to match your domain - -In the **App Dashboard URL** web page, go to Authentication / Settings and select Email Templates. - -Now open the "Reset Password" section and enter `https://.app.genez.io/reset-password`. - -:::info -Change `https://.app.genez.io/reset-password` to use the **Frontend URL** as returned by the genezio deploy command. -::: - - -## 3. Redeploy your project - -Finally, let's redeploy your project: - -```bash -genezio deploy -``` - -## 4. Test your deployed project +## Test your deployed app Go to the **Frontend URL** in your browser to test the newly created app. -## 5. Understand how your Refine app calls the Genezio backend. +## Understand how your Refine app calls the Genezio backend. Open the `client/src/App.tsx` file and see how the Admin component uses the authProvider and the dataProvider. -You will also see two resources, BlogPosts and Categories. These frontend resources have backend equivalents in the `server/` folder. For example, open the `server/Categories.ts` file to see how it's implemented. - -The server-side implementation uses a simple JSON to store the data. Next, I encourage you to go and replace this with an actual SQL table in your PostgreSQL database already created. See [this tutorial](/docs/tutorials/connect-to-postgres.md) to understand how to do this. +You will also see three resources - BlogPosts, Authors and Categories. These frontend resources have backend equivalents in the `server/` folder. For example, open the `server/Categories.ts` file to see how it's implemented. -## Support +## Support We invite you to join our community on [Discord](https://discord.gg/uc9H5YKjXv) for further information and help. From 6dd5838b0fbeb26222c02d3e467eb7cb2a9f2182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreia=20Oc=C4=83noaia?= Date: Tue, 3 Sep 2024 15:26:46 +0300 Subject: [PATCH 2/3] Update the databases page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andreia Ocănoaia --- docs/features/databases.md | 1 + docs/project-structure/genezio-configuration-file.md | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/features/databases.md b/docs/features/databases.md index dec2dbd..fef9fe2 100644 --- a/docs/features/databases.md +++ b/docs/features/databases.md @@ -46,6 +46,7 @@ services: This will automatically create and link a database named `my-database` in the `us-east-1` region. You can connect to it in the code using the environment variable `${_DATABASE_URL}`. +For example, if the database name is `my-postgres`, the environment variable will be `MY_POSTGRES_DATABASE_URL`. :::tip Use `${{services.databases..uri}}` in the `genezio.yaml` to access the connection URI. diff --git a/docs/project-structure/genezio-configuration-file.md b/docs/project-structure/genezio-configuration-file.md index fac1f30..6a8da1e 100644 --- a/docs/project-structure/genezio-configuration-file.md +++ b/docs/project-structure/genezio-configuration-file.md @@ -76,7 +76,7 @@ services: region: us-east-1 ``` -Enabling a database service will automatically set an environment variable `_DATABASE_URL` that can be used to connect to the database. +Enabling a database service will automatically set an environment variable `_DATABASE_URL` that can be used to connect to the database. For example, if the database name is `my-postgres`, the environment variable will be `MY_POSTGRES_DATABASE_URL`. This resource exposes `uri` as an output expression: `${{services.databases..uri}}`. @@ -103,7 +103,7 @@ The supported regions are: #### `type`: `string` **Optional** -The default value is `neon-postgres`. +The default value is `postgres-neon`. ### `authentication`: `Object` **Optional** From 1a6e9b60e2963e3760eaa25795f4c1a388e8d165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreia=20Oc=C4=83noaia?= Date: Tue, 3 Sep 2024 17:05:06 +0300 Subject: [PATCH 3/3] Add guide to write temporary files with Genezio Functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andreia Ocănoaia --- docs/tutorials/temporary-files.md | 67 +++++++++++++++++++++++++++++++ sidebars.js | 1 + 2 files changed, 68 insertions(+) create mode 100644 docs/tutorials/temporary-files.md diff --git a/docs/tutorials/temporary-files.md b/docs/tutorials/temporary-files.md new file mode 100644 index 0000000..df05ef7 --- /dev/null +++ b/docs/tutorials/temporary-files.md @@ -0,0 +1,67 @@ +--- +description: This tutorial explains how to use temporary files in Genezio functions. Learn how to create, read, and delete temporary files in your functions. +--- + +# Temporary Files in Genezio Functions + + + Temporary Files in Genezio Functions | Genezio Documentation + + +This tutorial will walk you through reading and writing temporary files from Genezio Functions. +We'll cover how bundling operates and how Genezio includes additional files for runtime use in your functions. + +## Bundling Genezio Functions + +Your application is by default bundled by Genezio to include all necessary user code and dependencies needed for runtime. + +You can ignore files or directories from the bundling process by adding them to the `.genezioignore` file in the root of your project. Learn more about [the `.genezioignore` file here](/docs/project-structure/.genezioignore). + +## Examples of reading files + +Use `process.cwd()` to determine the current directory of the Genezio Function. + +```typescript title="./server/index.mjs" +import fs from 'fs'; +import path from 'path'; + +export const handler = async () => { + const filePath = path.join(process.cwd(), 'test.md'); + + const data = fs.readFileSync(filePath, 'utf8'); + console.log("The file contents are:", data); + + return { + statusCode: 200, + body: data, + }; +}; +``` + +To deploy this function to Genezio, you have to configure the `genezio.yaml` file. Learn more about [the configuration file here](/docs/project-structure/genezio-configuration-file.md). + +## Examples of writing files + +Use `process.cwd()` to determine the current directory of the Genezio Function. + +```typescript title="./server/index.mjs" +import fs from 'fs'; +import path from 'path'; + +export const handler = async () => { + const filePath = path.join(process.cwd(), 'test.md'); + + fs.writeFileSync(filePath, '# Hello, World!'); + + return { + statusCode: 200, + body: 'File written successfully', + }; +}; +``` + +To deploy this function to Genezio, you have to configure the `genezio.yaml` file. Learn more about [the configuration file here](/docs/project-structure/genezio-configuration-file.md). + +**Note**: When using Function-as-a-Service (FaaS) platforms like Genezio, file system within these environments is ephemeral. This means that any files written to or modified within the function's execution environment will not persist after the function is killed. To use local files, you typically bundle them with your function during deployment, ensuring they are available at runtime. However, since the file system is temporary, any changes made to these files won't be saved after the function completes its execution. For persistent data storage, you'll need to use external storage solutions such a KV store or a database. + +Learn how to connect a Postgres or a Redis database to your Genezio function in the [Tutorials section](/docs/tutorials/). diff --git a/sidebars.js b/sidebars.js index 32a01d6..5651c7b 100644 --- a/sidebars.js +++ b/sidebars.js @@ -57,6 +57,7 @@ const sidebars = { "tutorials/connect-to-mongo-atlas", "tutorials/create-react-app-genezio-auth", "tutorials/create-react-app-genezio-google-oauth", + "tutorials/temporary-files", { type: "link", label: "Create your first Web3 App", // The link label