Skip to content

Commit

Permalink
Merge pull request #128 from OurFreeLight/dev
Browse files Browse the repository at this point in the history
0.8.92 merge
  • Loading branch information
ncoonrod authored Apr 22, 2024
2 parents c5bf6c6 + c169e2a commit 818d565
Show file tree
Hide file tree
Showing 10 changed files with 355 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@
"--trace-warnings"
],
"args": [
"--timeout", "6000",
"--timeout", "600000000",
"--colors",
"./build/tests/**/*.js"
"./build/tests/server/**/*.js"
],
"cwd": "${workspaceFolder}",
"envFile": "${workspaceFolder}/.env"
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{
"circleci.filters.branchFilter": "allBranches"
}
43 changes: 33 additions & 10 deletions builder/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ To stop the container enter:
./stop.sh
```

## Docker Environment Variables
## Container Environment Variables
* HOTSTAQ_VERSION
* Description: The global version of HotStaq to install.
* Type: string
* Default:
* HOTSITE_NAME
* Description: The name of the hotsite to use.
* Type: string
* Default:
* WEB_IMAGE
* Description: The image name of the docker image to be built.
* Type: string
Expand All @@ -41,22 +49,37 @@ To stop the container enter:
* Description: The start arguments to pass to HotStaq when starting the app.
* Type: string
* Default:
* SERVER_TYPE
* Description: The type of server to start. Can be:
* web
* api
* web-api
* LOG_LEVEL
* Description: Set the logging level. Can be:
* info
* warning
* error
* verbose
* all
* none
* Type: string
* Default: web-api
* Default: all
* BASE_URL
* Description: The base url to use for the web server.
* Type: string
* Default:
* BASE_API_URL
* Description: The base url to use for the api server.
* Type: string
* Default:
* HTTP_PORT
* Description: The http port to listen on.
* Description: The web http port to listen on.
* Type: number
* Default: 5000
* HTTPS_PORT
* Description: The https port to listen on.
* Description: The web https port to listen on.
* Type: number
* Default: 443
* API_HTTP_PORT
* Description: The api http port to listen on.
* Type: number
* Default:
* API_HTTPS_PORT
* Description: The api https port to listen on.
* Type: number
* Default: 443
* Default:
152 changes: 151 additions & 1 deletion creator/project/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,154 @@ npm run build-web
To generate the OpenAPI 3.0.0 YAML documentation enter:
```console
npm run build-doc
```
```

## Environment Variables
HotStaq can be configured in a variety of ways, and as such has a lot of environment variables that can be used.

## Server Environment Variables
* LOGGING_LEVEL
* Description: Set the logging level. Can be:
* info
* warning
* error
* verbose
* all
* none
* Type: string
* Default: all
* SERVER_TYPE
* Description: The type of server to start. Can be:
* web
* api
* web-api
* Type: string
* Default: web-api
* USE_HTTP
* Description: Forces the use of HTTP.
* Type: string
* Default: 1
* HTTP_PORT
* Description: The http port to listen on.
* Type: number
* Default: 5000
* HTTPS_PORT
* Description: The https port to listen on.
* Type: number
* Default:
* HTTPS_SSL_CERT
* Description: Sets the path to the TLS certificate to use when using HTTPS_PORT.
* Type: string
* Default:
* HTTPS_SSL_KEY
* Description: Sets the path to the TLS private key to use when using HTTPS_PORT.
* Type: string
* Default:
* HTTPS_SSL_CA
* Description: Sets the path to the TLS CA key to use when using HTTPS_PORT.
* Type: string
* Default:
* LISTEN_ADDR
* Description: The listen address to use.
* Type: string
* Default: 0.0.0.0
* JSON_LIMIT
* Description: Sets the max JSON limit. Uses the npm bytes library for parsing.
* Type: string
* Default: 1mb
* TEMP_UPLOAD_DIR
* Description: Sets the path to the temporary upload directory to use when a file is uploaded.
* Type: string
* Default: ./temp/
* TEMP_UPLOAD_DIR
* Description: Sets the path to the temporary upload directory to use when a file is uploaded.
* Type: string
* Default: ./temp/

## Database Environment Variables
* DATABASE_DISABLE
* Description: If set to 1, no database connection will be initiated.
* Type: string
* Default: 0
* DATABASE_TYPE
* Description: The type of database to connect to. Can be:
* none
* mysql
* influx
* Type: mysql
* Default: none
* DATABASE_SERVER
* Description: The database server address to connect to.
* Type: string
* Default:
* DATABASE_PORT
* Description: The database port to use to connect to the server.
* Type: string
* Default:
* DATABASE_USERNAME
* Description: The database username to use to connect to the server.
* Type: string
* Default:
* DATABASE_PASSWORD
* Description: The database password to use to connect to the server.
* Type: string
* Default:
* DATABASE_ORG
* Description: The database org to use to connect to the server.
* Type: string
* Default:
* DATABASE_TOKEN
* Description: The database token to use to connect to the server.
* Type: string
* Default:
* DATABASE_SCHEMA
* Description: The database schema to use.
* Type: string
* Default:
* DATABASE_CONNECTIONS_LIMIT
* Description: The database schema to use.
* Type: number
* Default: 10

## Testing Environment Variables
* SELENIUM_REMOTE_SERVER
* Description: The remote selenium server to connect to.
* Type: string
* Default:
* SELENIUM_WINDOW_WIDTH
* Description: The window width to use.
* Type: string
* Default:
* SELENIUM_WINDOW_HEIGHT
* Description: The window height to use.
* Type: string
* Default:
* USER_DATA_DIR
* Description: The data directory to use for the selected web browser.
* Type: string
* Default:
* TESTING_DEVTOOLS
* Description: When the web browser starts, the dev tools will open automatically.
* Type: number
* Default: 0
* TESTING_REMOTE_SERVER
* TESTING_RUN_HEADLESS
* Description: Configures testing for a remote server.
* Type: string
* Default: 0
* TESTER_LISTEN_ADDR
* Description: The listen address to use for testers.
* Type: string
* Default: 0.0.0.0
* TESTER_USE_HTTP
* Description: Forces the use of HTTP for testers.
* Type: string
* Default: 1
* TESTER_HTTP_PORT
* Description: The http port to listen on for testers.
* Type: number
* Default: 5000
* TESTER_HTTPS_PORT
* Description: The https port to listen on for testers.
* Type: number
* Default:
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hotstaq",
"version": "0.8.91",
"version": "0.8.92",
"description": "A friendly web framework that fits nicely into devops and CI/CD pipelines.",
"bin": {
"hotstaq": "./bin/hotstaq"
Expand Down
94 changes: 94 additions & 0 deletions src/Hot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,100 @@ export class Hot
*/
static jsScriptsStr: string = `<script type = "text/javascript">%JS_CODE%</script>`;

/**
* Get a validated URL parameter.
*
* @example
* ```ts
* <*
* const id = Hot.getUrlParam ('id', 'int');
* *>
*
* <div>The id is: ${id}</div>
* ```
*
* @param validation This parameter is for validating and sanitizing a URL parameter.
* If it's a string, the available options are:
* * int
* * This will only allow integers. parseInt will be called and will return an integer.
* * float
* * This will only allow floating point numbers. parseFloat will be called and will return a float.
* * email
* * Will verify that the string is in the form of an email address.
* * phone
* * Will verify that the string is in the form of an email address.
* * uuid
* * This will verify that the string is in the form of a UUID. It does not check if the UUID is valid.
* * string(number_of_chars)
* * This will only allow a string of the specified number of characters.
*
* If this is a function, this will call the supplied function to validate. Validation checks must happen
* in the function and return the sanitized value. It is simply a passthrough, be wise with this. Throw
* an error if the value is not valid.
*
* @returns Returns the URL parameter, only if it passes validation. If the parameter is not found,
* null will be returned.
*/
static getUrlParam (param: string, validation: string | ((param: any) => any)): any
{
const urlParams = new URLSearchParams (window.location.search);
const value = urlParams.get (param);

if (value == null)
return (null);

if (typeof (validation) === "string")
{
switch (validation)
{
case "int":
return (parseInt (value));
case "float":
return (parseFloat (value));
case "email":
{
const emailRegex = new RegExp ("^\\S+@\\S+\\.\\S+$");

if (emailRegex.test (value) === true)
return (value);

break;
}
case "phone":
{
const phoneRegex = new RegExp ("^\\+?([0-9 ]?){6,14}[0-9]$");

if (phoneRegex.test (value) === true)
return (value);

break;
}
case "uuid":
{
const uuidRegex = new RegExp ("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}");

if (uuidRegex.test (value) === true)
return (value);

break;
}
default:
if (validation.indexOf ("string") > -1)
{
const numChars = parseInt (validation.split ("(")[1].split (")")[0]);

if (value.length === numChars)
return (value);
}
break;
}

throw new Error (`getUrlParam retreiving parameter "${param}" using validation type "${validation}" failed.`);
}

return (validation (value));
}

/**
* Retrieve a file and echo out it's contents.
*/
Expand Down
1 change: 1 addition & 0 deletions src/HotDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export abstract class HotDB<DBType = any, DBResultType = any, DBSchema = HotDBSc
connectionStatus: ConnectionStatus;
/**
* The max number of database connections to maintain.
* @default 10
*/
connectionLimit: number;
/**
Expand Down
Loading

0 comments on commit 818d565

Please sign in to comment.