Skip to content

Commit

Permalink
Merge branch 'main' into feat/issuesDetails/routerAndController
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeGoodall committed Aug 8, 2024
2 parents af376e4 + b8d06ff commit 6799a7d
Show file tree
Hide file tree
Showing 27 changed files with 505 additions and 378 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ dist
.yarn/install-state.gz
.pnp.*

volume/cache

# playwright
/test-results/
/playwright-report/*
Expand Down
2 changes: 1 addition & 1 deletion config/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ aws: {
redis: {
secure: false,
host: 'redis',
port: '6379'
port: 6379
}
url: "http://localhost:8085"
1 change: 0 additions & 1 deletion config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ aws: {
bucket: '',
s3ForcePathStyle: false,
}
redis: false
# ToDo: url and name might need updating
url: 'https://check-planning.data.gov.uk'
serviceName: 'Provide planning and housing data for England'
Expand Down
2 changes: 1 addition & 1 deletion config/development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ aws: {
redis: {
secure: true,
host: 'development-pub-async-redis-3dqynz.serverless.euw2.cache.amazonaws.com',
port: '6379'
port: 6379
}
url: 'https://publish.development.digital-land.info/'
20 changes: 4 additions & 16 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
import HmpoConfig from 'hmpo-config'
import yaml from 'js-yaml'
import fs from 'fs'
import _ from 'lodash'

const readConfig = (config) => {
return yaml.load(fs.readFileSync(`./config/${config}.yaml`, 'utf8'))
}
import { combineConfigs, validateConfig } from './util.js'

/**
*
* @returns {{defaultConfig, environment}}
* @returns {{defaultConfig, environment, url}}
*/
const getConfig = () => {
const defaultConfig = readConfig('default')

const environment = process.env.NODE_ENV || process.env.ENVIRONMENT || 'production'

if (environment !== 'test') console.info('USING CONFIG: ' + environment)

const customConfig = readConfig(environment)

const combinedConfig = _.merge({}, defaultConfig, customConfig)
const combinedConfig = combineConfigs(environment)
validateConfig(combinedConfig)

const config = new HmpoConfig()
config.addConfig(combinedConfig)
Expand Down
2 changes: 1 addition & 1 deletion config/local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ aws: {
redis: {
secure: false,
host: 'localhost',
port: '6379'
port: 6379
}
port: 5000
url: 'http://localhost:5000/'
2 changes: 1 addition & 1 deletion config/production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ aws: {
redis: {
secure: true,
host: 'production-pub-async-redis-eihmmv.serverless.euw2.cache.amazonaws.com',
port: '6379'
port: 6379
}
url: 'https://publish.digital-land.info/'
smartlook: {
Expand Down
2 changes: 1 addition & 1 deletion config/staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ aws: {
redis: {
secure: true,
host: 'staging-pub-async-redis-kh1elu.serverless.euw2.cache.amazonaws.com',
port: '6379'
port: 6379
}
url: 'https://publish.staging.digital-land.info/'
72 changes: 72 additions & 0 deletions config/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import fs from 'fs'
import _ from 'lodash'
import yaml from 'js-yaml'
import * as v from 'valibot'

export const ConfigSchema = v.object({
port: v.pipe(v.integer(), v.minValue(1)),
asyncRequestApi: v.object({
url: v.url(),
port: v.pipe(v.integer(), v.minValue(1)),
requestsEndpoint: v.pipe(v.string(), v.nonEmpty()),
requestTimeout: v.number()
}),
maintenance: v.object({
serviceUnavailable: v.boolean(),
upTime: v.pipe(v.string(), v.nonEmpty())
}),
aws: v.object({
region: v.string(),
bucket: v.string(),
s3ForcePathStyle: v.boolean()
}),
redis: v.optional(
v.object({
secure: v.boolean(),
host: v.pipe(v.string(), v.nonEmpty()),
port: v.number()
})
),
url: v.url(),
serviceName: v.pipe(v.string(), v.nonEmpty()),
feedbackLink: v.url(),
email: v.object({
templates: v.object({
RequesetTemplateId: v.uuid(),
AcknowledgementTemplateId: v.uuid()
}),
dataManagementEmail: v.pipe(v.string(), v.email())
})
})

const readConfig = (config) => {
console.assert(config, 'config not specified')
return yaml.load(fs.readFileSync(`./config/${config}.yaml`, 'utf8'))
}

/**
* Reads configs from disk, based on env variables
* when 'environment' option not specified.
*
* @returns {Object}
*/
export function combineConfigs (environment) {
console.assert(environment, 'environment not specified')
const defaultConfig = readConfig('default')
const customConfig = readConfig(environment)
return _.merge({}, defaultConfig, customConfig)
}

export const validateConfig = (config) => {
try {
return v.parse(ConfigSchema, config)
} catch (error) {
console.error('invalid config', error.message)
for (const issue of error.issues) {
console.info(
`issue under path: [${issue.path.map((elem) => elem.key).join(', ')}]`
)
}
throw error
}
}
2 changes: 1 addition & 1 deletion config/wiremock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ asyncRequestApi: {
redis: {
secure: false,
host: 'localhost',
port: '6379'
port: 6379
}
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import express from 'express'
import dotenv from 'dotenv'
import logger from './src/utils/logger.js'
import { types } from './src/utils/logging.js'
import config from './config/index.js'

import { setupMiddlewares } from './src/serverSetup/middlewares.js'
Expand All @@ -18,7 +19,7 @@ dotenv.config()
const app = express()

setupMiddlewares(app)
setupSession(app)
await setupSession(app)
setupNunjucks({
app,
datasetNameMapping: await getDatasetSlugNameMapping()
Expand All @@ -28,5 +29,8 @@ setupSentry(app)
setupErrorHandlers(app)

app.listen(config.port, () => {
logger.info(`App listening on all interfaces (0.0.0.0) on port ${config.port}`)
logger.info({
message: `listening on all interfaces (0.0.0.0) on port ${config.port}`,
type: types.AppLifecycle
})
})
Loading

0 comments on commit 6799a7d

Please sign in to comment.