Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify the config to load from config.js and env variables instead of using config.json #8

Merged
merged 3 commits into from
Nov 21, 2024
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
17 changes: 13 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# Port used to serve the web application
HTTP_PORT=3030
DATABASE=marketplace_starter_js_development
DATABASE_USER=FILLME
DATABASE_PASSWORD=FILLME

# Database configuration
DB_NAME=marketplace_starter_js_development
DB_USERNAME=FILLME
DB_PASSWORD=FILLME
DB_HOST=localhost
DB_PORT=5432

# Basic Auth Configuration for Provisioning APIs
BASIC_AUTH_USERNAME=FILLME
BASIC_AUTH_PASSWORD=FILLME
QN_SSO_SECRET=FILLME

# JWT Configuration for SSO
QN_SSO_SECRET=FILLME
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ jobs:
run: |
cd webapp && cat > .env <<EOL
HTTP_PORT=3030
DATABASE=marketplace_starter_js_development
DATABASE_USER=postgres
DATABASE_PASSWORD=postgres
DB_USERNAME: postgres
DB_PASSWORD: postgres
DB_NAME: marketplace_starter_js_development
DB_HOST: localhost
DB_PORT: 5432
BASIC_AUTH_USERNAME=username
BASIC_AUTH_PASSWORD=password
QN_SSO_SECRET=jwt-secret
Expand Down Expand Up @@ -96,4 +98,4 @@ jobs:
run: ./cli/qn-marketplace-cli rpc --url http://localhost:3030/provision --rpc-method qn_test --rpc-url http://localhost:3030/rpc --rpc-params "[\"abc\"]" --basic-auth dXNlcm5hbWU6cGFzc3dvcmQ=

- name: Test SSO [OPTIONAL - remove from this yml file if your add-on does not have a dashboard]
run: ./cli/qn-marketplace-cli sso --basic-auth dXNlcm5hbWU6cGFzc3dvcmQ= --url http://localhost:3030/provision --jwt-secret jwt-secret --email [email protected] --name jon --org QuickNode
run: ./cli/qn-marketplace-cli sso --basic-auth dXNlcm5hbWU6cGFzc3dvcmQ= --url http://localhost:3030/provision --jwt-secret jwt-secret --email [email protected] --name jon --org QuickNode
44 changes: 44 additions & 0 deletions config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Load environment variables from the .env file
require("dotenv").config();

module.exports = {
// Configuration for the development environment
development: {
username: process.env.DB_USERNAME, // Database username for development
password: process.env.DB_PASSWORD, // Database password for development
database: process.env.DB_NAME, // Database name for development
host: process.env.DB_HOST, // Database host for development
port: process.env.DB_PORT, // Database port for development
dialect: "postgres", // Database dialect (PostgreSQL)
dialectOptions: {
ssl: false, // SSL is not used in development
},
},
// Configuration for the test environment
test: {
username: process.env.DB_USERNAME, // Database username for testing
password: process.env.DB_PASSWORD, // Database password for testing
database: process.env.DB_NAME, // Database name for testing
host: process.env.DB_HOST, // Database host for testing
port: process.env.DB_PORT, // Database port for testing
dialect: "postgres", // Database dialect (PostgreSQL)
dialectOptions: {
ssl: false,
},
},
// Configuration for the production environment
production: {
username: process.env.DB_USERNAME, // Database username for production
password: process.env.DB_PASSWORD, // Database password for production
database: process.env.DB_NAME, // Database name for production
host: process.env.DB_HOST, // Database host for production
port: process.env.DB_PORT, // Database port for production
dialect: "postgres", // Database dialect (PostgreSQL)
dialectOptions: {
ssl: {
require: true, // SSL is required in production
rejectUnauthorized: true,
},
},
},
};
23 changes: 0 additions & 23 deletions config/config.json

This file was deleted.

25 changes: 14 additions & 11 deletions src/models/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import Sequelize from 'sequelize';
import Sequelize from "sequelize";

import getAccountModel from './account';
import getEndpointModel from './endpoint';
import getAccountModel from "./account";
import getEndpointModel from "./endpoint";

// Set the environment and get the corresponding configuration
const env = process.env.NODE_ENV || "development";
const config = require("../../config/config")[env];

// Initialize Sequelize with database configuration
const sequelize = new Sequelize(
process.env.DATABASE,
process.env.DATABASE_USER,
process.env.DATABASE_PASSWORD,
{
dialect: 'postgres',
},
config.database,
config.username,
config.password,
config,
);

const models = {
Expand All @@ -18,11 +21,11 @@ const models = {
};

Object.keys(models).forEach((key) => {
if ('associate' in models[key]) {
if ("associate" in models[key]) {
models[key].associate(models);
}
});

export { sequelize };

export default models;
export default models;
Loading