Skip to content

Commit

Permalink
Add dependencies, eslint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jrock-3 committed Feb 29, 2024
1 parent 5b7c63a commit c5c1084
Show file tree
Hide file tree
Showing 9 changed files with 576 additions and 79 deletions.
15 changes: 8 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ schedule.scheduleJob('0 0 0 0 0', () => console.log('Hello Cron Job!')); // FIXM

const app = express();

const CLIENT_HOSTNAME = process.env.NODE_ENV === 'development' ?
`${process.env.DEV_CLIENT_HOSTNAME}:${process.env.DEV_CLIENT_PORT}`
: process.env.PROD_CLIENT_HOSTNAME;
const SERVER_PORT = process.env.NODE_ENV === 'development' ?
process.env.DEV_SERVER_PORT
: process.env.PROD_SERVER_PORT;
const CLIENT_HOSTNAME =
process.env.NODE_ENV === 'development'
? `${process.env.DEV_CLIENT_HOSTNAME}:${process.env.DEV_CLIENT_PORT}`
: process.env.PROD_CLIENT_HOSTNAME;
const SERVER_PORT =
process.env.NODE_ENV === 'development'
? process.env.DEV_SERVER_PORT
: process.env.PROD_SERVER_PORT;

app.use(
cors({
Expand All @@ -33,4 +35,3 @@ app.use('/', sampleRouter); // FIXME: delete sample endpoint
app.listen(SERVER_PORT, () => {
console.log(`Server listening on ${SERVER_PORT}`);
});

20 changes: 10 additions & 10 deletions common/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
const aws = require('aws-sdk');
const crypto = require('crypto');

const region = process.env.NODE_ENV === 'development' ?
process.env.DEV_S3_REGION
: process.env.PROD_S3_REGION;
const accessKeyId = process.env.NODE_ENV === 'development' ?
process.env.DEV_S3_ACCESS_KEY_ID
: process.env.PROD_S3_ACCESS_KEY_ID;
const secretAccessKey = process.env.NODE_ENV === 'development' ?
process.env.DEV_SECRET_ACCESS_KEY
: process.env.PROD_S3_SECRET_ACCESS_KEY;
const region =
process.env.NODE_ENV === 'development' ? process.env.DEV_S3_REGION : process.env.PROD_S3_REGION;
const accessKeyId =
process.env.NODE_ENV === 'development'
? process.env.DEV_S3_ACCESS_KEY_ID
: process.env.PROD_S3_ACCESS_KEY_ID;
const secretAccessKey =
process.env.NODE_ENV === 'development'
? process.env.DEV_SECRET_ACCESS_KEY
: process.env.PROD_S3_SECRET_ACCESS_KEY;

// initialize a S3 instance
const s3 = new aws.S3({
Expand Down Expand Up @@ -42,4 +43,3 @@ module.exports = {
s3,
getS3UploadURL,
};

21 changes: 12 additions & 9 deletions common/transporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ const nodemailer = require('nodemailer');

require('dotenv').config();

const user = process.env.NODE_ENV === 'development' ?
process.env.DEV_EMAIL_USERNAME
: process.env.PROD_EMAIL_USERNAME;
const pass = process.env.NODE_ENV === 'development' ?
process.env.DEV_EMAIL_PASSWORD
: process.env.PROD_EMAIL_PASSWORD;
const emailSender = process.env.NODE_ENV === 'development' ?
`${process.env.DEV_EMAIL_FIRSTNAME} ${process.env.DEV_EMAIL_LASTNAME}`
: `${process.env.PROD_EMAIL_FIRSTNAMS} ${process.env.DEV_EMAIL_LASTNAME}`;
const user =
process.env.NODE_ENV === 'development'
? process.env.DEV_EMAIL_USERNAME
: process.env.PROD_EMAIL_USERNAME;
const pass =
process.env.NODE_ENV === 'development'
? process.env.DEV_EMAIL_PASSWORD
: process.env.PROD_EMAIL_PASSWORD;
const emailSender =
process.env.NODE_ENV === 'development'
? `${process.env.DEV_EMAIL_FIRSTNAME} ${process.env.DEV_EMAIL_LASTNAME}`
: `${process.env.PROD_EMAIL_FIRSTNAMS} ${process.env.DEV_EMAIL_LASTNAME}`;

// sender information
const transport = {
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,26 @@
"*.js": "yarn run eslint"
},
"dependencies": {
"aws-sdk": "^2.1568.0",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"eslint": "^8.1.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-prettier": "^4.0.0",
"express": "^4.17.1",
"mongoose": "^8.2.0",
"mysql": "^2.18.1",
"node-schedule": "^2.1.1",
"nodemailer": "^6.9.10",
"nodemon": "^2.0.14",
"pg-promise": "^11.5.4",
"prettier": "^2.4.1"
},
"devDependencies": {
"eslint-config-prettier": "^8.3.0",
"lint-staged": "^11.2.6",
"lint-staged": "^11.2.6",
"husky": "^7.0.4"
"husky": "^7.0.4",
"lint-staged": "^11.2.6"
}
}
6 changes: 3 additions & 3 deletions routes/sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sampleRouter.use(express.json());
sampleRouter.get('/', async (req, res) => {
try {
// Query database
const data = { };
const data = {};

res.status(200).json(keysToCamel(data));
} catch (err) {
Expand All @@ -21,10 +21,10 @@ sampleRouter.get('/', async (req, res) => {

sampleRouter.post('/', async (req, res) => {
try {
const { _ } = req.body;
// Destructure req.body

// Do something with request body
const data = { };
const data = {};

res.status(200).json(keysToCamel(data));
} catch (err) {
Expand Down
12 changes: 5 additions & 7 deletions server/db-mongoose.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
// FIXME: keep file only if using mongodb
const mongoose = require("mongoose");
const mongoose = require('mongoose');

const mongoURI = process.env.NODE_ENV === 'development' ?
process.env.DEV_DB_URI
: process.env.PROD_DB_URI;
const mongoURI =
process.env.NODE_ENV === 'development' ? process.env.DEV_DB_URI : process.env.PROD_DB_URI;

mongoose.connect(mongoURI, {
useNewUrlParser: true,
useUnifiedTopology: true,
});

const mongoConnection = mongoose.connection;
mongoConnection.once("open", () => {
console.log("MongoDB database connection established successfully");
mongoConnection.once('open', () => {
console.log('MongoDB database connection established successfully');
});

module.exports = mongoose;

27 changes: 14 additions & 13 deletions server/db-mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

const mysql = require('mysql');

const host = process.env.NODE_ENV === 'development' ?
process.env.DEV_DB_HOSTNAME
: process.env.PROD_DB_HOSTNAME;
const user = process.env.NODE_ENV === 'development' ?
process.env.DEV_DB_USERNAME
: process.env.PROD_DB_USERNAME;
const password = process.env.NODE_ENV === 'development' ?
process.env.DEV_DB_PASSWORD
: process.env.PROD_DB_PASSWORD;
const database = process.env.NODE_ENV === 'development' ?
process.env.DEV_DB_NAME
: process.env.PROD_DB_NAME;
const host =
process.env.NODE_ENV === 'development'
? process.env.DEV_DB_HOSTNAME
: process.env.PROD_DB_HOSTNAME;
const user =
process.env.NODE_ENV === 'development'
? process.env.DEV_DB_USERNAME
: process.env.PROD_DB_USERNAME;
const password =
process.env.NODE_ENV === 'development'
? process.env.DEV_DB_PASSWORD
: process.env.PROD_DB_PASSWORD;
const database =
process.env.NODE_ENV === 'development' ? process.env.DEV_DB_NAME : process.env.PROD_DB_NAME;

const db = mysql.createConnection({
host,
Expand All @@ -25,4 +27,3 @@ const db = mysql.createConnection({
db.connect();

module.exports = { mysql, db };

32 changes: 16 additions & 16 deletions server/db-pgp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
const pgp = require('pg-promise')({});
require('dotenv').config();

const host = process.env.NODE_ENV === 'development' ?
process.env.DEV_DB_HOSTNAME
: process.env.PROD_DB_HOSTNAME;
const user = process.env.NODE_ENV === 'development' ?
process.env.DEV_DB_USERNAME
: process.env.PROD_DB_USERNAME;
const password = process.env.NODE_ENV === 'development' ?
process.env.DEV_DB_PASSWORD
: process.env.PROD_DB_PASSWORD;
const database = process.env.NODE_ENV === 'development' ?
process.env.DEV_DB_NAME
: process.env.PROD_DB_NAME;
const port = process.env.NODE_ENV === 'development' ?
process.env.DEV_DB_PORT
: process.env.PROB_DB_PORT;
const host =
process.env.NODE_ENV === 'development'
? process.env.DEV_DB_HOSTNAME
: process.env.PROD_DB_HOSTNAME;
const user =
process.env.NODE_ENV === 'development'
? process.env.DEV_DB_USERNAME
: process.env.PROD_DB_USERNAME;
const password =
process.env.NODE_ENV === 'development'
? process.env.DEV_DB_PASSWORD
: process.env.PROD_DB_PASSWORD;
const database =
process.env.NODE_ENV === 'development' ? process.env.DEV_DB_NAME : process.env.PROD_DB_NAME;
const port =
process.env.NODE_ENV === 'development' ? process.env.DEV_DB_PORT : process.env.PROB_DB_PORT;

const db = pgp({
host,
Expand All @@ -31,4 +32,3 @@ const db = pgp({
});

module.exports = { db, pgp };

Loading

0 comments on commit c5c1084

Please sign in to comment.