From 52a5b68590a2d5c445b7de8adb3da6c7bf978ef8 Mon Sep 17 00:00:00 2001 From: Evan Sellers Date: Fri, 17 May 2024 13:32:59 -0400 Subject: [PATCH] Updated Docs --- docs.json | 2 +- docs/api/components/parameters.mdx | 5 +++ docs/build/miscellaneous.mdx | 61 +++++++++++++++++++++++++++++- docs/structure.mdx | 1 + 4 files changed, 67 insertions(+), 2 deletions(-) diff --git a/docs.json b/docs.json index fa6d2fc..02d4bf5 100644 --- a/docs.json +++ b/docs.json @@ -18,7 +18,7 @@ ["Server Config", "/build/server-config"], ["Module Config", "/build/module-config"], ["Building a Module - WIP", "/build/building-a-module"], - ["Miscellaneous - WIP", "/build/miscellaneous"] + ["Miscellaneous", "/build/miscellaneous"] ] ], [ "API Reference", diff --git a/docs/api/components/parameters.mdx b/docs/api/components/parameters.mdx index 28489ff..41ee115 100644 --- a/docs/api/components/parameters.mdx +++ b/docs/api/components/parameters.mdx @@ -6,6 +6,11 @@ includes numbers and booleans. This class is very similar to the standard [URLSearchParams class](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) used in web APIs. +When parameters come from the [`Request`](/api/components/request) class, from a +URL they are automatically parsed (booleans and numbers) and seperated by commas. +See [request examples](/api/components/request#basic-get-request), for more +information. +
diff --git a/docs/build/miscellaneous.mdx b/docs/build/miscellaneous.mdx index 687fb2f..b5a8f77 100644 --- a/docs/build/miscellaneous.mdx +++ b/docs/build/miscellaneous.mdx @@ -1 +1,60 @@ -# Miscellaneous \ No newline at end of file +# Miscellaneous + + +## Environment Variables +Environment variables are a key part of configuring your SherpaJS application. +They allow you to set various configuration options and secrets without +hardcoding them into your application's codebase. + + +
+ + +### Loading Environment Variables +SherpaJS uses the `.env` file to load environment variables. This file should +be placed at the root of your project. When the system is compiled, the +variables defined in this file are automatically loaded into your server's +environment. + +Any environment variables provided by hosting services (such as Vercel or AWS) +are automatically included in your build. + +Environment varibles can also be added during build with the +[build command](/api/cli#build-command). + + +
+ + +### Automatic Parsing +SherpaJS automatically parses environment variables to their appropriate types: +- Strings remain as strings +- Booleans are converted to `true` or `false` +- Numbers are converted to numeric values + + +
+ + +### Example .env File +Here is an example of a `.env` file: + +```shell title=".env" +PORT=3000 # number +DATABASE_URL=mongodb://localhost:27017/mydatabase # string +JWT_SECRET=myverysecretkey # string +ENABLE_FEATURE_X=true # boolean +MAX_CONNECTIONS=100 # number +``` + +
+ + +### Best Practices +- **Security**: Never commit your `.env` file to version control. Add it + to your `.gitignore` file. +- **Defaults**: Provide sensible default values for environment variables + in your code. +- **Validation**: Validate the presence and format of critical environment + variables at the start of your application to avoid runtime errors. + diff --git a/docs/structure.mdx b/docs/structure.mdx index d09de7b..c655a11 100644 --- a/docs/structure.mdx +++ b/docs/structure.mdx @@ -27,6 +27,7 @@ Top-level files are used to configure SherpaJS and manage the environment. |---|---| | [`sherpa.server.ts`](/build/server-config) | SherpaJS server config | | [`sherpa.module.ts`](/build/module-config) | SherpaJS module config, *optional only if creating a module* | +| [`.env`](/build/miscellaneous#environment-variables) | Environment Varibles File |