Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,29 @@ The script ```$ migrateDbAndStartServer.sh``` will create the tables specified i
_NOTE: Databases should be already configured locally in `config/data_models_storage_config.json`_.


### Environment Variables

## Environment Variables

### Mandatory
* `ALLOW_ORIGIN` - Sets the `Access-Control-Allow-Origin` header to the specified value.
* `JWT_SECRET` - The secret string used to sign authorization tokens.

### Optional (without defaults)
* `MAIL_SERVICE` - For bulk add operations, the email service to use for sending progress reports.
* `MAIL_HOST` - Email service host (usually SMTP config).
* `MAIL_ACCOUNT` - Sender email account address.
* `MAIL_PASSWORD` - Sender email account password.

### Optional (with sensible defaults)
* `ERROR_LOG` - Debug logs verbosity. Can be either "verbose" or "compact". Default value is `compact`.
* `EXPORT_TIME_OUT` - Maximum amount of time in milliseconds before the server throws a timeout error when exporting data. Default is `3600`.
* `LIMIT_RECORDS` - Maximum number of records that each request can return, default value is `10000`.
* `PORT` - The port where the app is listening, default value is `3000`
* `ALLOW_ORIGIN` - In development mode we need to specify the header `Access-Control-Allow-Origin` so the SPA application can communicate with the server, default value is `http://localhost:8080`.
* `LIMIT_RECORDS` - Maximum number of records that each request can return, default value is 10000.
* `MAX_TIME_OUT` - Maximum number of milliseconds that a zendro server will wait to connect with another zendro server.
* `REQUIRE_SIGN_IN` - Boolean to toggle the required sign in to the graphql server
* `POST_REQUEST_MAX_BODY_SIZE` - Maximum size of the GraphQL request in MB. Default is `1mb`.
* `MAX_TIME_OUT` - Maximum number of milliseconds that a zendro server will wait to connect with another zendro server. Default value is `2000`.
* `REQUIRE_SIGN_IN` - Boolean to toggle the required sign in to the graphql server. Default is `true`.
* `SALT_ROUNDS` - Number of salt rounds when hashing a new password. Default is `10`.



## Examples

Expand Down
85 changes: 70 additions & 15 deletions config/globals.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,73 @@
require('dotenv').config();

module.exports = {
LIMIT_RECORDS : process.env.LIMIT_RECORDS || 10000,
PORT : process.env.PORT || 3000,
ALLOW_ORIGIN: process.env.ALLOW_ORIGIN || "http://localhost:8080",
JWT_SECRET: process.env.JWT_SECRET,
SALT_ROUNDS: process.env.SALT_ROUNDS || 10,
REQUIRE_SIGN_IN: process.env.REQUIRE_SIGN_IN === "false" ? false : true,
MAX_TIME_OUT: process.env.MAX_TIME_OUT || 2000,
POST_REQUEST_MAX_BODY_SIZE: process.env.POST_REQUEST_MAX_BODY_SIZE || '1mb',
ERROR_LOG: process.env.ERROR_LOG || 'compact',
MAIL_SERVICE: process.env.MAIL_SERVICE || "gmail",
MAIL_HOST: process.env.MAIL_HOST || "smtp.gmail.com",
MAIL_ACCOUNT: process.env.MAIL_ACCOUNT || "sci.db.service@gmail.com",
MAIL_PASSWORD: process.env.MAIL_PASSWORD || "SciDbServiceQAZ",
EXPORT_TIME_OUT: process.env.EXPORT_TIME_OUT || 3600
/**
* Mandatory variables
*/
const ALLOW_ORIGIN = process.env.ALLOW_ORIGIN;
const JWT_SECRET = process.env.JWT_SECRET;

if (!ALLOW_ORIGIN || !JWT_SECRET) {
throw new Error('Some mandatory environment variables have not been set\n', {
ALLOW_ORIGIN,
JWT_SECRET,
})
}

/**
* Optional variables with no defaults
*/

const MAIL_ACCOUNT = process.env.MAIL_ACCOUNT;
const MAIL_HOST = process.env.MAIL_HOST;
const MAIL_PASSWORD = process.env.MAIL_PASSWORD;
const MAIL_SERVICE = process.env.MAIL_SERVICE;

if (!MAIL_ACCOUNT || !MAIL_HOST || !MAIL_PASSWORD || !MAIL_SERVICE) {
console.warn('WARNING: BulkAdd email service has not been properly configured', {
MAIL_ACCOUNT,
MAIL_HOST,
MAIL_PASSWORD,
MAIL_SERVICE,
})
}

/**
* Optional variables with sensible defaults
*/

// Listening port
const PORT = process.env.PORT || 3000;

// Logging
const ERROR_LOG = process.env.ERROR_LOG || 'compact';

// Request Limits
const LIMIT_RECORDS = process.env.LIMIT_RECORDS || 10000;
const POST_REQUEST_MAX_BODY_SIZE = process.env.POST_REQUEST_MAX_BODY_SIZE || '1mb';

// Security
const REQUIRE_SIGN_IN = process.env.REQUIRE_SIGN_IN === "false" ? false : true;
const SALT_ROUNDS = process.env.SALT_ROUNDS || 10;

// Timeouts
const MAX_TIME_OUT = process.env.MAX_TIME_OUT || 2000;
const EXPORT_TIME_OUT = process.env.EXPORT_TIME_OUT || 3600

const config = {
LIMIT_RECORDS,
PORT,
ALLOW_ORIGIN,
JWT_SECRET,
SALT_ROUNDS,
REQUIRE_SIGN_IN,
MAX_TIME_OUT,
POST_REQUEST_MAX_BODY_SIZE,
ERROR_LOG,
MAIL_SERVICE,
MAIL_HOST,
MAIL_ACCOUNT,
MAIL_PASSWORD,
EXPORT_TIME_OUT,
}

module.exports = config
5 changes: 5 additions & 0 deletions utils/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ const path = require('path');

module.exports = {
sendEmail: function (dst_email, subj, message, att){

if (!Globals.MAIL_ACCOUNT || !Globals.MAIL_HOST || !Globals.MAIL_PASSWORD || !Globals.MAIL_SERVICE) {
throw new Error('BulkAdd Email Service has not been configured');
}

console.log(`${dst_email}, ${message}, ${Globals.MAIL_ACCOUNT}, ${Globals.MAIL_PASSWORD}`);

let transporter = NodeMailer.createTransport(SmtpTransport({
Expand Down