Skip to content

Commit

Permalink
Merge pull request #254 from Genez-io/dev
Browse files Browse the repository at this point in the history
Updates on IaC
  • Loading branch information
andreia-oca authored Sep 3, 2024
2 parents 521e6cb + de393fe commit 49f46b2
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 42 deletions.
1 change: 1 addition & 0 deletions docs/features/databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_NAME>_DATABASE_URL}`.
For example, if the database name is `my-postgres`, the environment variable will be `MY_POSTGRES_DATABASE_URL`.

:::tip
Use `${{services.databases.<database-name>.uri}}` in the `genezio.yaml` to access the connection URI.
Expand Down
46 changes: 6 additions & 40 deletions docs/frameworks/refine.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
```

<h3> 3. Run the refine App locally </h3>
Expand Down Expand Up @@ -106,52 +106,18 @@ $ App Dashboard URL: https://app.genez.io/project/<project-id>/<stage-id>
$ Frontend URL: https://<subdomain>.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://<subdomain>.app.genez.io/reset-password`.

:::info
Change `https://<subdomain>.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 <a href="#support" id="support"></a>
## Support

We invite you to join our community on [Discord](https://discord.gg/uc9H5YKjXv) for further information and help.

Expand Down
4 changes: 2 additions & 2 deletions docs/project-structure/genezio-configuration-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ services:
region: us-east-1
```

Enabling a database service will automatically set an environment variable `<DATABASE_NAME>_DATABASE_URL` that can be used to connect to the database.
Enabling a database service will automatically set an environment variable `<DATABASE_NAME>_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.<database-name>.uri}}`.

Expand All @@ -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**

Expand Down
67 changes: 67 additions & 0 deletions docs/tutorials/temporary-files.md
Original file line number Diff line number Diff line change
@@ -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

<head>
<title>Temporary Files in Genezio Functions | Genezio Documentation</title>
</head>

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/).
1 change: 1 addition & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 49f46b2

Please sign in to comment.