-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #433 from ever-co/develop
Release
- Loading branch information
Showing
17 changed files
with
213 additions
and
39 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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Environment | ||
NODE_ENV=development | ||
TR_PORT=3000 | ||
TR_SECRET=supersecretkey | ||
TR_VIRTUAL_HOST=http://localhost:8080 | ||
TR_PUBLIC_DIR=/path/to/public | ||
TR_TEMPLATES_DIR=/path/to/templates | ||
|
||
# CORS and Logging | ||
TR_CORS_ENABLED=true | ||
TR_ACCESS_LOGS_ENABLED=true | ||
|
||
# Authentication | ||
TR_AUTH_TOKEN_EXPIRES=86400 | ||
TR_SIGNUPS_ENABLED=true | ||
|
||
# Database Configuration | ||
TR_DB_TYPE=mysql | ||
TR_DB_HOST=localhost | ||
TR_DB_PORT=3306 | ||
TR_DB_USER=myuser | ||
TR_DB_PASSWORD=mypassword | ||
TR_DB_DATABASE=mydatabase | ||
|
||
# Database Migration | ||
TR_DB_AUTOMIGRATE=true | ||
|
||
# Project Limits | ||
TR_MAX_PROJECTS_PER_USER=100 | ||
TR_DEFAULT_PROJECT_PLAN=open-source | ||
|
||
# Import Settings | ||
TR_IMPORT_MAX_NESTED_LEVELS=5 | ||
|
||
# Google OAuth Provider | ||
TR_AUTH_GOOGLE_ENABLED=false | ||
TR_AUTH_GOOGLE_CLIENT_SECRET=your-google-client-secret | ||
TR_AUTH_GOOGLE_CLIENT_ID=your-google-client-id | ||
TR_AUTH_GOOGLE_REDIRECT_URL=http://localhost:3000/auth/google/callback | ||
|
||
# Mail Configuration | ||
TR_MAIL_DEBUG=true | ||
TR_MAIL_SENDER=[email protected] | ||
TR_MAIL_HOST=smtp.mailtrap.io | ||
TR_MAIL_PORT=587 | ||
TR_MAIL_SECURE=false | ||
TR_MAIL_REJECT_SELF_SIGNED=true | ||
TR_MAIL_USER=myuser | ||
TR_MAIL_PASSWORD=mypassword |
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 |
---|---|---|
|
@@ -33,3 +33,5 @@ yarn-error.log | |
/**/.cache | ||
|
||
.vscode/ | ||
|
||
.env |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { join } from 'path'; | ||
// see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import | ||
import * as dotenv from 'dotenv'; | ||
dotenv.config({ path: join(__dirname, '../../.env') }); | ||
|
||
const env = process.env; | ||
|
||
/** | ||
* Checks for the presence of critical environment variables and logs warnings if any are missing. | ||
* This function logs a warning if `TR_SECRET` is not set, indicating that a default value will be used. | ||
* This helps ensure that necessary environment variables are defined for security and configuration purposes. | ||
*/ | ||
export function checkEnvVariables() { | ||
// Check TR_SECRET | ||
if (!env.TR_SECRET) { | ||
console.warn('TR_SECRET not set. Default value will be used. Please make sure you set it to your own value for security reasons in production!'); | ||
} | ||
|
||
// Check Google Auth Configuration | ||
if (env.TR_AUTH_GOOGLE_ENABLED === 'true') { | ||
const missingVars = []; | ||
|
||
if (!env.TR_AUTH_GOOGLE_CLIENT_SECRET) { | ||
missingVars.push('TR_AUTH_GOOGLE_CLIENT_SECRET'); | ||
} | ||
if (!env.TR_AUTH_GOOGLE_CLIENT_ID) { | ||
missingVars.push('TR_AUTH_GOOGLE_CLIENT_ID'); | ||
} | ||
if (!env.TR_AUTH_GOOGLE_REDIRECT_URL) { | ||
missingVars.push('TR_AUTH_GOOGLE_REDIRECT_URL'); | ||
} | ||
|
||
if (missingVars.length > 0) { | ||
console.warn( | ||
`You enabled Google Auth with TR_AUTH_GOOGLE_ENABLED = true, but did not set one or more required environment variables: ${missingVars.join(', ')}.`, | ||
); | ||
} | ||
} else { | ||
console.info( | ||
`Google Auth is disabled. To enable, set TR_AUTH_GOOGLE_ENABLED = true and define the required environment variables: TR_AUTH_GOOGLE_CLIENT_SECRET, TR_AUTH_GOOGLE_CLIENT_ID, and TR_AUTH_GOOGLE_REDIRECT_URL.`, | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Closable } from 'types'; | ||
import * as process from 'process'; | ||
|
||
/** | ||
* Sets up a shutdown handler for graceful application termination. | ||
* | ||
* This function listens for the SIGINT signal (typically triggered by pressing Ctrl+C) | ||
* and ensures that all provided resources are closed gracefully before the application exits. | ||
* | ||
* @param closables - An array of objects implementing the Closable interface, each containing a `close` method that returns a Promise. | ||
* This method is expected to clean up or release resources associated with each object. | ||
*/ | ||
export function setupShutdownHandler(closables: Closable[]) { | ||
process.on('SIGINT', async () => { | ||
console.log('Shutdown signal received. Initiating graceful shutdown...'); | ||
console.log(`Total resources to close: ${closables.length}`); | ||
|
||
try { | ||
for (const [index, closable] of closables.entries()) { | ||
await closable.close(); | ||
console.log(`Resource ${index + 1} closed successfully.`); | ||
} | ||
} catch (error) { | ||
console.error('Error occurred while closing resources:', error); | ||
} finally { | ||
process.exit(1); | ||
} | ||
}); | ||
} |
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,10 @@ | ||
/** | ||
* Defines a contract for objects that can be closed gracefully. | ||
* | ||
* Any class implementing this interface should provide a `close` method | ||
* that performs cleanup or resource release and returns a Promise that | ||
* resolves when the operation is complete. | ||
*/ | ||
export interface Closable { | ||
close(): Promise<void>; | ||
} |
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,17 @@ | ||
import { snakeCase } from 'typeorm/util/StringUtils'; | ||
import { config } from '../config'; | ||
|
||
// TypeORM fails to properly quote camelCase aliases with PostgreSQL | ||
// https://github.com/typeorm/typeorm/issues/10961 | ||
export const resolveColumnName = (columnName: string): string => { | ||
if (!columnName) { | ||
throw new Error('Column name cannot be empty'); | ||
} | ||
|
||
// convert only for postgres until typeorm has a fix | ||
if (config.db.default.type === 'postgres') { | ||
return snakeCase(columnName); | ||
} | ||
|
||
return columnName; | ||
}; |
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
Oops, something went wrong.