Skip to content

Commit

Permalink
Moved config to json
Browse files Browse the repository at this point in the history
  • Loading branch information
jzongker committed Nov 10, 2021
1 parent e56ae7a commit d95968d
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 46 deletions.
8 changes: 8 additions & 0 deletions config/dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"appEnv": "dev",
"appName": "AccessApi",
"contentRoot": "http://localhost:3402",
"fileStore": "disk",
"mailSystem": "SMTP",
"s3Bucket": ""
}
8 changes: 8 additions & 0 deletions config/prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"appEnv": "prod",
"appName": "AccessApi",
"contentRoot": "https://content.churchapps.org",
"fileStore": "S3",
"mailSystem": "SES",
"s3Bucket": "churchapps-content"
}
8 changes: 8 additions & 0 deletions config/staging.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"appEnv": "staging",
"appName": "AccessApi",
"contentRoot": "https://content.staging.churchapps.org",
"fileStore": "S3",
"mailSystem": "SES",
"s3Bucket": "staging-churchapps-content"
}
18 changes: 4 additions & 14 deletions dotenv.sample.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
# Modify and save this file as ".env"
API_ENV=dev
APP_NAME=AttendanceApi

# Node.js server configuration
APP_ENV=dev
CONNECTION_STRING=mysql://
ENCRYPTION_KEY=encryptionKey
JWT_SECRET=this is a test key that is a sentence
SERVER_PORT=8085

# MySql configuration
DB_HOST=localhost
DB_DATABASE=attendance
DB_USER=root
DB_PASSWORD=

JWT_SECRET_KEY=this is a test key that is a sentence
JWT_EXPIRATION=2 days
10 changes: 6 additions & 4 deletions lambda.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const { createServer, proxy } = require('aws-serverless-express');
const { init } = require('./dist/App');
const { Pool } = require('./dist/apiBase/pool');
const { Environment } = require('./dist/helpers/Environment');

Environment.init(process.env.APP_ENV);
Pool.initPool();

module.exports.universal = function universal(event, context) {
init().then(app => {
const server = createServer(app);
return proxy(server, event, context);
});
init().then(app => {
const server = createServer(app);
return proxy(server, event, context);
});

}
2 changes: 1 addition & 1 deletion src/apiBase
22 changes: 22 additions & 0 deletions src/helpers/Environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import fs from "fs";
import path from "path";

import { EnvironmentBase } from "../apiBase";

export class Environment extends EnvironmentBase {

static init(environment: string) {
let file = "dev.json";
if (environment === "staging") file = "staging.json";
if (environment === "prod") file = "prod.json";


const relativePath = "../../config/" + file;
const physicalPath = path.resolve(__dirname, relativePath);

const json = fs.readFileSync(physicalPath, "utf8");
const data = JSON.parse(json);
this.populateBase(data);
}

}
10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { init } from "./App";
import { Pool } from "./apiBase/pool";
const port = process.env.SERVER_PORT;
import { Environment } from './helpers/Environment';

const port = process.env.SERVER_PORT;
Environment.init(process.env.APP_ENV);
Pool.initPool();

init().then(app => {
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}/`);
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}/`);
});
});
48 changes: 25 additions & 23 deletions tools/initdb.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
import dotenv from "dotenv";
import { Environment } from "../src/helpers/Environment";
import { Pool } from "../src/apiBase/pool";
import { DBCreator } from "../src/apiBase/tools/DBCreator"

const init = async () => {
dotenv.config();
console.log("Connecting");
Pool.initPool();
dotenv.config();
Environment.init(process.env.APP_ENV);
console.log("Connecting");
Pool.initPool();

const attendanceTables: { title: string, file: string }[] = [
{ title: "Campuses", file: "campuses.mysql" },
{ title: "Services", file: "services.mysql" },
{ title: "Service Times", file: "serviceTimes.mysql" },
{ title: "Group Service Times", file: "groupServiceTimes.mysql" },
{ title: "Sessions", file: "sessions.mysql" },
{ title: "Visits", file: "visits.mysql" },
{ title: "Visit Sessions", file: "visitSessions.mysql" }
];
const attendanceTables: { title: string, file: string }[] = [
{ title: "Campuses", file: "campuses.mysql" },
{ title: "Services", file: "services.mysql" },
{ title: "Service Times", file: "serviceTimes.mysql" },
{ title: "Group Service Times", file: "groupServiceTimes.mysql" },
{ title: "Sessions", file: "sessions.mysql" },
{ title: "Visits", file: "visits.mysql" },
{ title: "Visit Sessions", file: "visitSessions.mysql" }
];

await DBCreator.init(["Settings"]);
await initTables("Attendance", attendanceTables);
await DBCreator.init(["Settings"]);
await initTables("Attendance", attendanceTables);
}

const initTables = async (displayName: string, tables: { title: string, file: string }[]) => {
console.log("");
console.log("SECTION: " + displayName);
for (const table of tables) await DBCreator.runScript(table.title, "./tools/dbScripts/" + table.file, false);
console.log("");
console.log("SECTION: " + displayName);
for (const table of tables) await DBCreator.runScript(table.title, "./tools/dbScripts/" + table.file, false);
}

init()
.then(() => { console.log("Database Created"); process.exit(0); })
.catch((ex) => {
console.log(ex);
console.log("Database not created due to errors");
process.exit(0);
});
.then(() => { console.log("Database Created"); process.exit(0); })
.catch((ex) => {
console.log(ex);
console.log("Database not created due to errors");
process.exit(0);
});

0 comments on commit d95968d

Please sign in to comment.