Skip to content
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
62 changes: 28 additions & 34 deletions src/client-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,36 @@
/**
* When running application in slow network condition (reproducible using 3G), the client-config.js might be loaded twice.
* This results to issues like `Uncaught SyntaxError: "identifier scheme has already been declared at (client-config.js:1:1")`.
*
*
* On high level, refreshing the browser window requests new document page. The document page includes script tag to load client-config.js.
* If the network is slow, the browser might start loading and executing client-config.js again before the previous one is torn down, causing the error.
*
*
*/
;(function initClientConfig() {

window.config = {
API_GATEWAY_URL: 'http://localhost:7070/',
CONFIG_API_URL: 'http://localhost:2021',
LOGIN_URL: 'http://localhost:3020',
AUTH_URL: 'http://localhost:7070/auth/',
MINIO_BUCKET: 'ocrvs',
MINIO_URL: 'http://localhost:3535/ocrvs/',
MINIO_BASE_URL: 'http://localhost:3535', // URL without path/bucket information, used for file uploads, v2
COUNTRY_CONFIG_URL: 'http://localhost:3040',
// Country code in uppercase ALPHA-3 format
COUNTRY: 'FAR',
LANGUAGES: 'en,fr',
SENTRY: '',
DASHBOARDS: [
{
id: 'leaderboards',
title: {
id: 'navigation.leaderboards',
defaultMessage: 'Development dashboard',
description: 'Menu item for development dashboard'
},
url: 'http://localhost:3040/ping',
}
],
// NOTE: This is not valid javascript until replaced during build time.
// IIFE just reveals it.
FEATURES: {
// The V2_EVENTS variable is passed down from src/index.ts:309
V2_EVENTS: {{ V2_EVENTS }}
window.config = {
API_GATEWAY_URL: 'http://localhost:7070/',
CONFIG_API_URL: 'http://localhost:2021',
LOGIN_URL: 'http://localhost:3020',
AUTH_URL: 'http://localhost:7070/auth/',
MINIO_BUCKET: 'ocrvs',
MINIO_URL: 'http://localhost:3535/ocrvs/',
MINIO_BASE_URL: 'http://localhost:3535', // URL without path/bucket information, used for file uploads, v2
COUNTRY_CONFIG_URL: 'http://localhost:3040',
// Country code in uppercase ALPHA-3 format
COUNTRY: 'FAR',
LANGUAGES: 'en,fr',
SENTRY: '',
DASHBOARDS: [
{
id: 'leaderboards',
title: {
id: 'navigation.leaderboards',
defaultMessage: 'Development dashboard',
description: 'Menu item for development dashboard'
},
url: 'http://localhost:3040/ping'
}
],
FEATURES: {}
}
}
})()
})()
9 changes: 3 additions & 6 deletions src/client-config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
/**
* When running application in slow network condition (reproducible using 3G), the client-config.js might be loaded twice.
* This results to issues like `Uncaught SyntaxError: "identifier scheme has already been declared at (client-config.js:1:1")`.
*
*
* On high level, refreshing the browser window requests new document page. The document page includes script tag to load client-config.js.
* If the network is slow, the browser might start loading and executing client-config.js again before the previous one is torn down, causing the error.
*
*
*/
;(function initClientConfig() {
const scheme = window.location.protocol // "http:" or "https:"
Expand Down Expand Up @@ -66,9 +66,6 @@
],
// NOTE: This is not valid javascript until replaced during build time.
// IIFE just reveals it.
FEATURES: {
// The V2_EVENTS variable is passed down from src/index.ts:309
V2_EVENTS: {{ V2_EVENTS }}
}
FEATURES: {}
}
})()
1 change: 0 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ export const CHECK_INVALID_TOKEN = env.CHECK_INVALID_TOKEN

export const PRODUCTION = env.isProd
export const QA_ENV = env.QA_ENV
export const V2_EVENTS = env.V2_EVENTS
export const ANALYTICS_DATABASE_URL = env.ANALYTICS_DATABASE_URL
1 change: 0 additions & 1 deletion src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const env = cleanEnv(process.env, {
devDefault: 'http://localhost:5050/confirm/registration'
}),
QA_ENV: bool({ default: false }),
V2_EVENTS: bool({ default: false }),
ANALYTICS_DATABASE_URL: url({
devDefault:
'postgres://events_analytics:analytics_password@localhost:5432/events',
Expand Down
8 changes: 1 addition & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require('dotenv').config()

import StreamArray from 'stream-json/streamers/StreamArray'
import path from 'path'
import Handlebars from 'handlebars'
import * as Hapi from '@hapi/hapi'
import * as Pino from 'hapi-pino'
import * as JWT from 'hapi-auth-jwt2'
Expand All @@ -25,7 +24,6 @@ import {
DOMAIN,
LOGIN_URL,
SENTRY_DSN,
V2_EVENTS,
COUNTRY_CONFIG_HOST,
COUNTRY_CONFIG_PORT,
CHECK_INVALID_TOKEN,
Expand Down Expand Up @@ -318,11 +316,7 @@ export async function createServer() {
? '/client-config.prod.js'
: '/client-config.js'

const template = Handlebars.compile(
readFileSync(join(__dirname, file), 'utf8')
)
const result = template({ V2_EVENTS })
return h.response(result).type('application/javascript')
return h.file(join(__dirname, file))
},
options: {
auth: false,
Expand Down
Loading