-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into SW-233-update-translations
- Loading branch information
Showing
12 changed files
with
93 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { AuthenticatedRequest } from '../../interfaces/authenticated-request'; | ||
import { ServiceContainer } from '../../interfaces/service-container'; | ||
|
||
declare module 'express-serve-static-core' { | ||
interface Request extends ServiceContainer, AuthenticatedRequest {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { User } from './user.interface'; | ||
|
||
export interface AuthenticatedRequest { | ||
user?: User; | ||
jwt?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Locale } from '../enums/locale'; | ||
import { StatsWalesApi } from '../services/stats-wales-api'; | ||
|
||
export interface ServiceContainer { | ||
swapi: StatsWalesApi; | ||
buildUrl: (path: string, locale: Locale, query?: Record<string, string>) => string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { NextFunction, Request, Response } from 'express'; | ||
|
||
import { Locale } from '../enums/locale'; | ||
import { StatsWalesApi } from '../services/stats-wales-api'; | ||
|
||
import { localeUrl } from './language-switcher'; | ||
|
||
// initialise any request-scoped services required by the app and store them on the request object for later use | ||
// see interfaces/service-container.ts and @types/express/index.d.ts for details | ||
export const initServices = (req: Request, res: Response, next: NextFunction): void => { | ||
if (!/^\/(public|css|assets)/.test(req.originalUrl)) { | ||
req.swapi = new StatsWalesApi(req.language as Locale, req.cookies.jwt); | ||
req.buildUrl = localeUrl; // for controllers | ||
res.locals.buildUrl = localeUrl; // for templates | ||
} | ||
next(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.