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

Chore/change node env of local dev to expect dev #659

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
2 changes: 1 addition & 1 deletion src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const config = convict({
env: {
doc: "The application environment.",
env: "NODE_ENV",
format: ["dev", "test", "prod", "staging"],
format: ["dev", "test", "prod", "staging", "vapt"],
default: "dev",
},
port: {
Expand Down
2 changes: 1 addition & 1 deletion src/logger/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const metadataRequest = Bluebird.promisify(
// TODO: Check this env var as it is not in example
const LOG_GROUP_NAME = `${process.env.AWS_BACKEND_EB_ENV_NAME}/nodejs.log`
const IS_PROD_ENV =
NODE_ENV !== "LOCAL_DEV" && NODE_ENV !== "DEV" && NODE_ENV !== "test"
NODE_ENV !== "dev" && NODE_ENV !== "staging" && NODE_ENV !== "test"
const IS_TEST_ENV = NODE_ENV === "test"

function timestampGenerator() {
Expand Down
7 changes: 3 additions & 4 deletions src/routes/v1/auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { config } from "@config/config"

import { isSecure } from "@root/utils/auth-utils"

const axios = require("axios")
const express = require("express")
const queryString = require("query-string")
Expand All @@ -26,10 +28,8 @@ const router = express.Router()
const CLIENT_ID = config.get("github.clientId")
const CLIENT_SECRET = config.get("github.clientSecret")
const REDIRECT_URI = config.get("github.redirectUri")
const AUTH_TOKEN_EXPIRY_MS = config.get("auth.tokenExpiry")
const CSRF_TOKEN_EXPIRY_MS = 600000
const FRONTEND_URL = config.get("app.frontendUrl")
const NODE_ENV = config.get("env")

const CSRF_COOKIE_NAME = "isomer-csrf"
const COOKIE_NAME = "isomercms"
Expand All @@ -53,8 +53,7 @@ async function authRedirect(req, res) {
const cookieSettings = {
expires: csrfTokenExpiry,
httpOnly: true,
secure:
NODE_ENV !== "DEV" && NODE_ENV !== "LOCAL_DEV" && NODE_ENV !== "test",
secure: isSecure,
}

const token = jwtUtils.signToken({ state })
Expand Down
6 changes: 1 addition & 5 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import InfraService from "@services/infra/InfraService"
import ReviewRequestService from "@services/review/ReviewRequestService"

import { apiLogger } from "./middleware/apiLogger"
import { AuthorizationMiddleware } from "./middleware/authorization"
import { NotificationOnEditHandler } from "./middleware/notificationOnEditHandler"
import getAuthenticatedSubrouterV1 from "./routes/v1/authenticated"
import getAuthenticatedSitesSubrouterV1 from "./routes/v1/authenticatedSites"
Expand All @@ -58,6 +57,7 @@ import CollaboratorsService from "./services/identity/CollaboratorsService"
import LaunchClient from "./services/identity/LaunchClient"
import LaunchesService from "./services/identity/LaunchesService"
import { rateLimiter } from "./services/utilServices/RateLimiter"
import { isSecure } from "./utils/auth-utils"

const path = require("path")

Expand Down Expand Up @@ -89,12 +89,8 @@ const express = require("express")
const helmet = require("helmet")
const createError = require("http-errors")

const NODE_ENV = config.get("env")
const SESSION_SECRET = config.get("auth.sessionSecret")

const isSecure =
NODE_ENV !== "DEV" && NODE_ENV !== "LOCAL_DEV" && NODE_ENV !== "test"

const SequelizeStore = SequelizeStoreFactory(session.Store)
const sessionMiddleware = session({
store: new SequelizeStore({
Expand Down
4 changes: 2 additions & 2 deletions src/services/identity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ const NODE_ENV = config.get("env")
const OTP_SECRET = config.get("auth.otpSecret")
const OTP_EXPIRY = config.get("auth.otpExpiry")

const IS_LOCAL_DEV = NODE_ENV === "LOCAL_DEV"
const IS_DEV = NODE_ENV === "dev"

// TODO: To remove TOTP
const totpGenerator = new TotpGenerator({
secret: OTP_SECRET,
expiry: OTP_EXPIRY,
})

const smsClient = IS_LOCAL_DEV
const smsClient = IS_DEV
? ({
sendSms: (_mobileNumber: string, message: string) => logger.info(message),
} as SmsClient)
Expand Down
6 changes: 2 additions & 4 deletions src/services/utilServices/MailClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ export default MailClient
const NODE_ENV = config.get("env")
const POSTMAN_API_KEY = config.get("postman.apiKey")

const IS_LOCAL_DEV = NODE_ENV === "LOCAL_DEV"
const IS_DEV = NODE_ENV === "dev"

const mockMailer = {
sendMail: (email: string, subject: string, html: string) =>
logger.info(`Mock email sent to <${email}>, subject: ${subject}\n${html}`),
} as MailClient
export const mailer = IS_LOCAL_DEV
? mockMailer
: new MailClient(POSTMAN_API_KEY)
export const mailer = IS_DEV ? mockMailer : new MailClient(POSTMAN_API_KEY)
2 changes: 1 addition & 1 deletion src/utils/auth-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { config } = require("@config/config")
const NODE_ENV = config.get("env")

function isSecure() {
return NODE_ENV !== "DEV" && NODE_ENV !== "LOCAL_DEV" && NODE_ENV !== "test"
return NODE_ENV !== "dev" && NODE_ENV !== "test"
}

module.exports = {
Expand Down
7 changes: 3 additions & 4 deletions src/utils/mutex-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ const { ConflictError } = require("@errors/ConflictError")
const NODE_ENV = config.get("env")
const MUTEX_TABLE_NAME = config.get("mutexTableName")

const IS_LOCAL_DEV =
NODE_ENV === "LOCAL_DEV" || NODE_ENV === "test" || NODE_ENV === "vapt"
const IS_DEV = NODE_ENV === "dev" || NODE_ENV === "test" || NODE_ENV === "vapt"
const mockMutexObj = {}

// Dynamodb constants
Expand All @@ -34,7 +33,7 @@ const lock = async (siteName) => {
const ONE_MIN_FROM_CURR_DATE_IN_SECONDS_FROM_EPOCH_TIME =
Math.floor(new Date().valueOf() / 1000) + 60

if (!IS_LOCAL_DEV) {
if (!IS_DEV) {
const params = {
TableName: MUTEX_TABLE_NAME,
Item: {
Expand All @@ -60,7 +59,7 @@ const lock = async (siteName) => {
}

const unlock = async (siteName) => {
if (IS_LOCAL_DEV) return mockUnlock(siteName)
if (IS_DEV) return mockUnlock(siteName)

try {
const params = {
Expand Down