diff --git a/resources/views/index.ejs b/resources/views/index.ejs index 7252354..3f16ecd 100644 --- a/resources/views/index.ejs +++ b/resources/views/index.ejs @@ -15,6 +15,9 @@
+ diff --git a/service/frontend/index.ts b/service/frontend/index.ts index 98f8fe7..969dacb 100644 --- a/service/frontend/index.ts +++ b/service/frontend/index.ts @@ -1 +1,4 @@ -console.log('index.ts') +const welcomePhrases = window.config.welcomePhrases + +const app: HTMLElement = document.getElementById('app')! +app.innerHTML = welcomePhrases.map(phrase => `

${phrase}

`).join('') diff --git a/service/server/ExpressServer.ts b/service/server/ExpressServer.ts index 10e206d..139d991 100644 --- a/service/server/ExpressServer.ts +++ b/service/server/ExpressServer.ts @@ -12,6 +12,7 @@ import { CatEndpoints } from './cats/CatEndpoints' import { RequestServices } from './types/CustomRequest' import { addServicesToRequest } from './middlewares/ServiceDependenciesMiddleware' import { Environment } from './Environment' +import { FrontendContext } from '../shared/FrontendContext' /** * Abstraction around the raw Express.js server and Nodes' HTTP server. @@ -76,8 +77,14 @@ export class ExpressServer { this.prepareAssets() this.configureStaticAssets(server) - const renderPage = (template: string) => async (req: Request, res: Response, next: NextFunction) => { - res.type('text/html').render(template, { cssFiles: this.cssFiles }) + const context: FrontendContext = { + cssFiles: this.cssFiles, + config: { + welcomePhrases: [ 'Bienvenue', 'Welcome', 'Willkommen', 'Welkom', 'Hoş geldin', 'Benvenuta', 'Bienvenido' ] + } + } + const renderPage = (template: string) => async (req: Request, res: Response, _: NextFunction) => { + res.type('text/html').render(template, context) } server.get('/', noCache, renderPage('index')) diff --git a/service/shared/FrontendContext.d.ts b/service/shared/FrontendContext.d.ts new file mode 100644 index 0000000..12a1099 --- /dev/null +++ b/service/shared/FrontendContext.d.ts @@ -0,0 +1,8 @@ +export interface FrontendConfig { + welcomePhrases: string[] +} + +export interface FrontendContext { + cssFiles?: string[] + config: FrontendConfig +} diff --git a/service/shared/Window.d.ts b/service/shared/Window.d.ts new file mode 100644 index 0000000..5821c67 --- /dev/null +++ b/service/shared/Window.d.ts @@ -0,0 +1,7 @@ +import { FrontendConfig } from './FrontendContext' + +declare global { + interface Window { + config: FrontendConfig + } +}