refactor: rename AUTO_ACTIVATE and SERVER_PORT

This commit is contained in:
Pierre-Louis Mercereau
2020-04-08 16:24:14 +02:00
parent 39bc253604
commit 05fe19417b
7 changed files with 24 additions and 15 deletions

View File

@@ -2,7 +2,7 @@ FROM node:12-alpine
ARG NODE_ENV=production
ENV NODE_ENV $NODE_ENV
ENV SERVER_PORT 3000
ENV PORT 3000
# git is required for testing with jest --watch
RUN if [ "$NODE_ENV" != "production" ]; then apk update && apk upgrade && apk add git; fi
@@ -16,6 +16,6 @@ COPY src src
ADD . .
HEALTHCHECK --interval=5s --timeout=5s --retries=3 CMD wget localhost:${SERVER_PORT}/healthz -q -O - > /dev/null 2>&1
HEALTHCHECK --interval=5s --timeout=5s --retries=3 CMD wget localhost:${PORT}/healthz -q -O - > /dev/null 2>&1
CMD ["yarn", "start"]

View File

@@ -20,7 +20,7 @@
| ----------------------------- | ------- | ----------- |
| `HASURA_ENDPOINT` | | |
| `HASURA_GRAPHQL_ADMIN_SECRET` | | |
| `SERVER_PORT` | 3000 | |
| `PORT` | 3000 | |
| `JWT_SECRET_KEY` | | |
| `JWT_ALGORITHM` | RS256 | |
| `JWT_EXPIRES_IN` | 15 | |

View File

@@ -3,7 +3,12 @@
import 'jest-extended'
import { JWT } from 'jose'
import { AUTO_ACTIVATE, HIBP_ENABLED, SERVER_URL, SMTP_ENABLED } from '@shared/config'
import {
AUTO_ACTIVATE_USER_ON_REGISTRATION,
HIBP_ENABLED,
SERVER_URL,
SMTP_ENABLED
} from '@shared/config'
import { HasuraAccountData, generateRandomString } from '@shared/helpers'
import { deleteMailHogEmail, mailHogSearch } from '@shared/test-utils'
@@ -33,7 +38,9 @@ const password = generateRandomString()
const agent = request(app)
it('should create an account', async () => {
const { status } = await agent.post('/auth/register').send({ email, password , user_data: { name: 'Test name' } })
const { status } = await agent
.post('/auth/register')
.send({ email, password, user_data: { name: 'Test name' } })
expect(status).toEqual(204)
})
@@ -49,7 +56,7 @@ it('should tell the account already exists', async () => {
/**
* * Only run this test if auto activation is disabled
*/
const manualActivationIt = !AUTO_ACTIVATE ? it : it.skip
const manualActivationIt = !AUTO_ACTIVATE_USER_ON_REGISTRATION ? it : it.skip
manualActivationIt('should activate the account', async () => {
let activateLink: string
if (SMTP_ENABLED) {

View File

@@ -1,4 +1,4 @@
import { AUTO_ACTIVATE, SERVER_URL, SMTP_ENABLED } from '@shared/config'
import { AUTO_ACTIVATE_USER_ON_REGISTRATION, SERVER_URL, SMTP_ENABLED } from '@shared/config'
import { Request, Response } from 'express'
import { asyncWrapper, checkHibp, hashPassword, selectAccount } from '@shared/helpers'
@@ -37,7 +37,7 @@ async function registerAccount({ body }: Request, res: Response): Promise<unknow
throw Boom.badImplementation()
}
if (!AUTO_ACTIVATE && SMTP_ENABLED) {
if (!AUTO_ACTIVATE_USER_ON_REGISTRATION && SMTP_ENABLED) {
try {
await emailClient.send({
template: 'confirm',

View File

@@ -17,7 +17,7 @@ export const {
* App settings.
*/
SERVER_URL,
SERVER_PORT = 3000,
PORT = 3000,
REDIRECT_URL_ERROR,
REDIRECT_URL_SUCCESS,
@@ -63,7 +63,9 @@ export const {
// Boolean environment variables are stored as string, we must transform them into booleans.
const getBooleanEnv = (envVar: string): boolean => process.env[envVar]?.toLowerCase() === 'true'
export const AUTO_ACTIVATE = getBooleanEnv('AUTO_ACTIVATE')
export const AUTO_ACTIVATE_USER_ON_REGISTRATION = getBooleanEnv(
'AUTO_ACTIVATE_USER_ON_REGISTRATION'
)
export const HIBP_ENABLED = getBooleanEnv('HIBP_ENABLED')
export const SMTP_ENABLED = getBooleanEnv('SMTP_ENABLED')
export const SMTP_SECURE = getBooleanEnv('SMTP_SECURE') // note: false disables SSL (deprecated)

View File

@@ -1,7 +1,7 @@
import { HasuraAccountData } from '@shared/helpers'
import { SuperTest, Test, agent } from 'supertest'
import { AUTO_ACTIVATE } from '@shared/config'
import { AUTO_ACTIVATE_USER_ON_REGISTRATION } from '@shared/config'
import { request as admin } from '@shared/request'
import { app } from '../server'
import { deleteEmailsOfAccount, TestAccount, createAccount } from '@shared/test-utils'
@@ -23,7 +23,7 @@ beforeAll(async () => {
// * Create a mock account
const { email, password } = createAccount()
await request.post('/auth/register').send({ email, password })
if (!AUTO_ACTIVATE) {
if (!AUTO_ACTIVATE_USER_ON_REGISTRATION) {
const hasuraData = (await admin(selectAccountByEmail, { email })) as HasuraAccountData
const ticket = hasuraData.auth_accounts[0].ticket
await request.get(`/auth/account/activate?ticket=${ticket}`)

View File

@@ -1,6 +1,6 @@
import { SERVER_PORT } from '@shared/config'
import { PORT } from '@shared/config'
import { app } from './server'
export const server = app.listen(SERVER_PORT, () => {
console.log(`Running on http://localhost:${SERVER_PORT}`)
export const server = app.listen(PORT, () => {
console.log(`Running on http://localhost:${PORT}`)
})