Skip to content

Commit

Permalink
Merge pull request #9 from DEFRA/add-app-path-prefix-back-in
Browse files Browse the repository at this point in the history
Add app path prefix work back in
  • Loading branch information
feedmypixel authored Feb 12, 2024
2 parents 63d6033 + e4e7cf3 commit a4b7a44
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 14 deletions.
8 changes: 7 additions & 1 deletion src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ const config = convict({
assetPath: {
doc: 'Asset path',
format: String,
default: './public',
default: 'public',
env: 'ASSET_PATH'
},
appPathPrefix: {
doc: 'Application url path prefix',
format: String,
default: '/aqie-front-end',
env: 'APP_PATH_PREFIX'
},
isProduction: {
doc: 'If this application running in the production environment',
format: Boolean,
Expand Down
8 changes: 6 additions & 2 deletions src/config/nunjucks/context/build-navigation.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { config } from '~/src/config'

const appPathPrefix = config.get('appPathPrefix')

function buildNavigation(request) {
return [
{
text: 'Home',
url: '/',
isActive: request.path === '/'
url: appPathPrefix,
isActive: request.path === appPathPrefix
}
]
}
Expand Down
20 changes: 12 additions & 8 deletions src/config/nunjucks/context/build-navigation.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { config } from '~/src/config'
import { buildNavigation } from '~/src/config/nunjucks/context/build-navigation'

const appPathPrefix = config.get('appPathPrefix')
const mockRequest = ({ path = '' } = {}) => ({
path
})
Expand All @@ -10,17 +12,19 @@ describe('#buildNavigation', () => {
{
isActive: false,
text: 'Home',
url: '/'
url: appPathPrefix
}
])
})
test('Should provide expected highlighted navigation details', async () => {
expect(await buildNavigation(mockRequest({ path: '/' }))).toEqual([
{
isActive: true,
text: 'Home',
url: '/'
}
])
expect(await buildNavigation(mockRequest({ path: appPathPrefix }))).toEqual(
[
{
isActive: true,
text: 'Home',
url: appPathPrefix
}
]
)
})
})
3 changes: 2 additions & 1 deletion src/config/nunjucks/context/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { buildNavigation } from '~/src/config/nunjucks/context/build-navigation'

const logger = createLogger()
const assetPath = config.get('assetPath')
const appPathPrefix = config.get('appPathPrefix')

const manifestPath = path.resolve(
config.get('root'),
Expand All @@ -28,7 +29,7 @@ function context(request) {
getAssetPath: function (asset) {
const webpackAssetPath = webpackManifest[asset]

return `${assetPath}/${webpackAssetPath}`
return `${appPathPrefix}/${assetPath}/${webpackAssetPath}`
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ async function startServer() {

server.logger.info('Server started successfully')
server.logger.info(
`Access your frontend on http://localhost:${config.get('port')}`
`Access your frontend on http://localhost:${config.get('port')}${config.get(
'appPathPrefix'
)}`
)
}

Expand Down
4 changes: 3 additions & 1 deletion src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ async function createServer() {
await server.register(secureContext)
}

await server.register(router)
await server.register(router, {
routes: { prefix: config.get('appPathPrefix') }
})

await server.register(nunjucksConfig)

Expand Down

0 comments on commit a4b7a44

Please sign in to comment.