From a8c9364520afa80deedac11b4561dd358a993b37 Mon Sep 17 00:00:00 2001 From: Justyn Oh Date: Mon, 15 May 2023 17:14:01 +0800 Subject: [PATCH] chore: delete home folder, rename frontend to frontend-old and frontend-new to frontend --- src/app/loaders/express/index.ts | 4 +- .../frontend-new/frontend.controller.ts | 107 -------- .../modules/frontend-new/frontend.routes.ts | 12 - .../__tests__/frontend.controller.spec.ts | 0 .../frontend-old/frontend.controller.ts | 172 +++++++++++++ .../frontend.middlewares.ts | 0 .../modules/frontend-old/frontend.routes.ts | 47 ++++ .../frontend.service.ts | 0 .../modules/frontend/frontend.controller.ts | 235 +++++++----------- src/app/modules/frontend/frontend.routes.ts | 43 +--- .../home/__tests__/home.controller.spec.ts | 19 -- src/app/modules/home/home.controller.ts | 10 - src/app/modules/home/home.routes.ts | 7 - src/app/routes/api/v3/client/client.routes.ts | 2 +- 14 files changed, 311 insertions(+), 347 deletions(-) delete mode 100644 src/app/modules/frontend-new/frontend.controller.ts delete mode 100644 src/app/modules/frontend-new/frontend.routes.ts rename src/app/modules/{frontend => frontend-old}/__tests__/frontend.controller.spec.ts (100%) create mode 100644 src/app/modules/frontend-old/frontend.controller.ts rename src/app/modules/{frontend => frontend-old}/frontend.middlewares.ts (100%) create mode 100644 src/app/modules/frontend-old/frontend.routes.ts rename src/app/modules/{frontend => frontend-old}/frontend.service.ts (100%) delete mode 100644 src/app/modules/home/__tests__/home.controller.spec.ts delete mode 100644 src/app/modules/home/home.controller.ts delete mode 100644 src/app/modules/home/home.routes.ts diff --git a/src/app/loaders/express/index.ts b/src/app/loaders/express/index.ts index 8562fb1dca..ab8b8bbfe9 100644 --- a/src/app/loaders/express/index.ts +++ b/src/app/loaders/express/index.ts @@ -11,8 +11,8 @@ import { AuthRouter } from '../../modules/auth/auth.routes' import { ExamplesRouter } from '../../modules/examples/examples.routes' import { AdminFormsRouter } from '../../modules/form/admin-form/admin-form.routes' import { PublicFormRouter } from '../../modules/form/public-form/public-form.routes' -import { FrontendRouter as OldFrontendRouter } from '../../modules/frontend/frontend.routes' -import { FrontendRouter } from '../../modules/frontend-new/frontend.routes' +import { FrontendRouter } from '../../modules/frontend/frontend.routes' +import { FrontendRouter as OldFrontendRouter } from '../../modules/frontend-old/frontend.routes' import { MYINFO_ROUTER_PREFIX } from '../../modules/myinfo/myinfo.constants' import { MyInfoRouter } from '../../modules/myinfo/myinfo.routes' import { SgidRouter } from '../../modules/sgid/sgid.routes' diff --git a/src/app/modules/frontend-new/frontend.controller.ts b/src/app/modules/frontend-new/frontend.controller.ts deleted file mode 100644 index 7fd4e8427a..0000000000 --- a/src/app/modules/frontend-new/frontend.controller.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { readFileSync } from 'fs' -import { escape } from 'html-escaper' -import { get } from 'lodash' -import path from 'path' - -import { FormStatus } from '../../../../shared/types' -import { createLoggerWithLabel } from '../../config/logger' -import { ControllerHandler } from '../core/core.types' -import * as FormService from '../form/form.service' -import { createMetatags } from '../form/public-form/public-form.service' -import { RedirectParams } from '../form/public-form/public-form.types' - -const logger = createLoggerWithLabel(module) - -const reactFrontendPath = path.resolve('dist/frontend') -const reactHtml = readFileSync(path.join(reactFrontendPath, 'index.html'), { - encoding: 'utf8', -}) - -type MetaTags = { - title: string - description: string - image: string -} -const replaceWithMetaTags = ({ - title, - description, - image, -}: MetaTags): string => { - return reactHtml - .replace(/(__OG_TITLE__)/g, escape(title)) - .replace(/(__OG_DESCRIPTION__)/g, escape(description)) - .replace(/(__OG_IMAGE__)/g, escape(image)) -} - -const serveFormReact = - (isPublicForm: boolean): ControllerHandler => - async (req, res) => { - let tags: MetaTags = { - title: 'FormSG', - description: 'Trusted form manager of the Singapore Government', - image: 'og-img-metatag-nonpublicform.png', - } - - if (isPublicForm && get(req.params, 'formId')) { - tags = await getPublicFormMetaTags(get(req.params, 'formId') ?? '') - } - - const reactHtmlWithMetaTags = replaceWithMetaTags(tags) - - return ( - res - // Prevent index.html from being cached by browsers. - .setHeader('Cache-Control', 'no-cache') - .send(reactHtmlWithMetaTags) - ) - } - -const getPublicFormMetaTags = async (formId: string): Promise => { - const createMetatagsResult = await createMetatags({ - formId, - }) - - if (createMetatagsResult.isErr()) { - logger.error({ - message: 'Error fetching metatags', - meta: { - action: 'getPublicFormMetaTags', - formId, - }, - error: createMetatagsResult.error, - }) - return { - title: 'FormSG', - description: '', - image: 'og-img-metatag-publicform.png', - } - } else { - const { title, description } = createMetatagsResult.value - return { - title: title, - description: description ?? '', - image: 'og-img-metatag-publicform.png', - } - } -} - -export const servePublicForm: ControllerHandler< - RedirectParams, - unknown, - unknown, - Record -> = async (req, res, next) => { - const formResult = await FormService.retrieveFormKeysById(req.params.formId, [ - 'responseMode', - 'status', - ]) - - const isPublicForm = - !formResult.isErr() && formResult.value.status === FormStatus.Public - - return serveFormReact(isPublicForm)(req, res, next) -} - -export const serveDefault: ControllerHandler = (req, res, next) => { - return serveFormReact(/* isPublic= */ false)(req, res, next) -} diff --git a/src/app/modules/frontend-new/frontend.routes.ts b/src/app/modules/frontend-new/frontend.routes.ts deleted file mode 100644 index 743b6973ec..0000000000 --- a/src/app/modules/frontend-new/frontend.routes.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Router } from 'express' - -import * as FrontendController from './frontend.controller' - -export const FrontendRouter = Router() - -FrontendRouter.get( - '/:formId([a-fA-F0-9]{24})', - FrontendController.servePublicForm, -) - -FrontendRouter.get('*', FrontendController.serveDefault) diff --git a/src/app/modules/frontend/__tests__/frontend.controller.spec.ts b/src/app/modules/frontend-old/__tests__/frontend.controller.spec.ts similarity index 100% rename from src/app/modules/frontend/__tests__/frontend.controller.spec.ts rename to src/app/modules/frontend-old/__tests__/frontend.controller.spec.ts diff --git a/src/app/modules/frontend-old/frontend.controller.ts b/src/app/modules/frontend-old/frontend.controller.ts new file mode 100644 index 0000000000..cb2165cdbe --- /dev/null +++ b/src/app/modules/frontend-old/frontend.controller.ts @@ -0,0 +1,172 @@ +import ejs from 'ejs' +import { StatusCodes } from 'http-status-codes' + +import { ClientEnvVars } from '../../../../shared/types/core' +import { createLoggerWithLabel } from '../../config/logger' +import { createReqMeta } from '../../utils/request' +import { ControllerHandler } from '../core/core.types' + +import { validateGenerateRedirectParams } from './frontend.middlewares' +import { getClientEnvVars } from './frontend.service' + +const logger = createLoggerWithLabel(module) + +/** + * Handler for GET /frontend/datalayer endpoint. + * @param req - Express request object + * @param res - Express response object + * @returns Templated Javascript code for the frontend to initialise Google Tag Manager + */ +export const addGoogleAnalyticsData: ControllerHandler< + unknown, + string | { message: string } +> = (req, res) => { + const js = ` + window.dataLayer = window.dataLayer || []; + function gtag(){dataLayer.push(arguments);} + gtag('js', new Date()); + gtag('config', '<%= GATrackingID%>', { + 'send_page_view': false, + 'app_name': '<%= appName%>', + 'cookie_flags': 'samesite=none;secure', + }); + ` + try { + const ejsRendered = ejs.render(js, req.app.locals) + return res.type('text/javascript').status(StatusCodes.OK).send(ejsRendered) + } catch (err) { + logger.error({ + message: 'Error returning datalayer', + meta: { + action: 'datalayer', + ...createReqMeta(req), + }, + error: err, + }) + return res.status(StatusCodes.BAD_REQUEST).json({ + message: 'There was an unexpected error. Please refresh and try again.', + }) + } +} + +/** + * Handler for GET /frontend/environment endpoint. + * @param req - Express request object + * @param res - Express response object + * @returns Templated Javascript code with environment variables for the frontend + */ +export const addEnvVarData: ControllerHandler = ( + req, + res, +) => { + try { + return res + .type('text/javascript') + .status(StatusCodes.OK) + .send(req.app.locals.environment) + } catch (err) { + logger.error({ + message: 'Error returning environment', + meta: { + action: 'environment', + ...createReqMeta(req), + }, + error: err, + }) + return res.status(StatusCodes.BAD_REQUEST).json({ + message: 'There was an unexpected error. Please refresh and try again.', + }) + } +} + +/** + * Handler for GET /frontend/env endpoint. + * @returns the environment variables needed to hydrate the frontend. + */ +export const handleGetEnvironment: ControllerHandler = ( + _req, + res, +) => { + return res.json(getClientEnvVars()) +} + +/** + * Handler for GET /frontend/redirect endpoint. + * @param req - Express request object + * @param res - Express response object + * @returns Templated Javascript code for the frontend that redirects to specific form url + */ +export const _generateRedirectUrl: ControllerHandler< + unknown, + string | { message: string }, + unknown, + { redirectPath: string } +> = (req, res) => { + const js = ` + // Update hash to match form id + window.location.hash = "#!/<%= redirectPath%>" + // Change url from form.gov.sg/123#!123 to form.gov.sg/#!/123 + window.history.replaceState("","", "/#!/<%= redirectPath%>") + ` + // If there are multiple query params, '&' is html-encoded as '&', which is not valid URI + // Prefer to replace just '&' instead of using <%- to output unescaped values into the template + // As this could potentially introduce security vulnerability + // See https://ejs.co/#docs for tags + try { + const ejsRendered = ejs.render(js, req.query).replace(/&/g, '&') + return res.type('text/javascript').status(StatusCodes.OK).send(ejsRendered) + } catch (err) { + logger.error({ + message: 'Error returning redirectLayer', + meta: { + action: 'redirectlayer', + ...createReqMeta(req), + }, + error: err, + }) + return res.status(StatusCodes.BAD_REQUEST).json({ + message: 'There was an unexpected error. Please refresh and try again.', + }) + } +} + +export const generateRedirectUrl = [ + validateGenerateRedirectParams, + _generateRedirectUrl, +] as ControllerHandler[] + +// Duplicated here since the feature manager is being deprecated. +// TODO (#2147): delete this. +enum FeatureNames { + Captcha = 'captcha', + GoogleAnalytics = 'google-analytics', + Sentry = 'sentry', + Sms = 'sms', + SpcpMyInfo = 'spcp-myinfo', + VerifiedFields = 'verified-fields', + WebhookVerifiedContent = 'webhook-verified-content', +} + +/** + * Handler for GET /frontend/features endpoint. + * @param _req - Express request object + * @param res - Express response object + * @returns Current featureManager states + * @deprecated as the feature manager has been deprecated. This endpoint + * now hardcodes the feature states to support old clients. + * TODO (#2147): delete this + */ +export const showFeaturesStates: ControllerHandler< + unknown, + Record +> = (_req, res) => { + return res.json({ + [FeatureNames.Captcha]: true, + [FeatureNames.Sms]: true, + [FeatureNames.SpcpMyInfo]: true, + [FeatureNames.VerifiedFields]: true, + [FeatureNames.GoogleAnalytics]: true, + [FeatureNames.WebhookVerifiedContent]: true, + [FeatureNames.Sentry]: true, + }) +} diff --git a/src/app/modules/frontend/frontend.middlewares.ts b/src/app/modules/frontend-old/frontend.middlewares.ts similarity index 100% rename from src/app/modules/frontend/frontend.middlewares.ts rename to src/app/modules/frontend-old/frontend.middlewares.ts diff --git a/src/app/modules/frontend-old/frontend.routes.ts b/src/app/modules/frontend-old/frontend.routes.ts new file mode 100644 index 0000000000..7f97568823 --- /dev/null +++ b/src/app/modules/frontend-old/frontend.routes.ts @@ -0,0 +1,47 @@ +import { Router } from 'express' + +import * as FrontendServerController from './frontend.controller' + +/** @deprecated use client router in src/app/routes/api/v3/client/client.routes.ts instead. */ +export const FrontendRouter = Router() + +/** + * @deprecated use routes in src/app/routes/api/v3/client/client.routes.ts instead + * Generate the templated Javascript code for the frontend to initialise Google Tag Manager + * Code depends on whether googleAnalyticsFeature.isEnabled + * @route GET /frontend/datalayer + * @return 200 when code generation is successful + * @return 400 when code generation fails + */ +FrontendRouter.get( + '/datalayer', + FrontendServerController.addGoogleAnalyticsData, +) + +/** + * @deprecated use routes in src/app/routes/api/v3/client/client.routes.ts instead + * Generate the templated Javascript code with environment variables for the frontend + * @route GET /frontend/environment + * @return 200 when code generation is successful + * @return 400 when code generation fails + */ +FrontendRouter.get('/environment', FrontendServerController.addEnvVarData) + +/** + * @deprecated use routes in src/app/routes/api/v3/client/client.routes.ts instead + * Generate a json of current activated features + * @route GET /frontend/features + * @return json with featureManager.states + * @deprecated + * TODO (#2147): delete this + */ +FrontendRouter.get('/features', FrontendServerController.showFeaturesStates) + +/** + * @deprecated use routes in src/app/routes/api/v3/client/client.routes.ts instead + * Generate the javascript code to redirect to the correct url + * @route GET /frontend/redirect + * @return 200 when redirect code is successful + * @return 400 when redirect code fails + */ +FrontendRouter.get('/redirect', FrontendServerController.generateRedirectUrl) diff --git a/src/app/modules/frontend/frontend.service.ts b/src/app/modules/frontend-old/frontend.service.ts similarity index 100% rename from src/app/modules/frontend/frontend.service.ts rename to src/app/modules/frontend-old/frontend.service.ts diff --git a/src/app/modules/frontend/frontend.controller.ts b/src/app/modules/frontend/frontend.controller.ts index 13165884b3..7fd4e8427a 100644 --- a/src/app/modules/frontend/frontend.controller.ts +++ b/src/app/modules/frontend/frontend.controller.ts @@ -1,172 +1,107 @@ -import ejs from 'ejs' -import { StatusCodes } from 'http-status-codes' +import { readFileSync } from 'fs' +import { escape } from 'html-escaper' +import { get } from 'lodash' +import path from 'path' -import { ClientEnvVars } from '../../../../shared/types/core' +import { FormStatus } from '../../../../shared/types' import { createLoggerWithLabel } from '../../config/logger' -import { createReqMeta } from '../../utils/request' import { ControllerHandler } from '../core/core.types' - -import { validateGenerateRedirectParams } from './frontend.middlewares' -import { getClientEnvVars } from './frontend.service' +import * as FormService from '../form/form.service' +import { createMetatags } from '../form/public-form/public-form.service' +import { RedirectParams } from '../form/public-form/public-form.types' const logger = createLoggerWithLabel(module) -/** - * Handler for GET /frontend/datalayer endpoint. - * @param req - Express request object - * @param res - Express response object - * @returns Templated Javascript code for the frontend to initialise Google Tag Manager - */ -export const addGoogleAnalyticsData: ControllerHandler< - unknown, - string | { message: string } -> = (req, res) => { - const js = ` - window.dataLayer = window.dataLayer || []; - function gtag(){dataLayer.push(arguments);} - gtag('js', new Date()); - gtag('config', '<%= GATrackingID%>', { - 'send_page_view': false, - 'app_name': '<%= appName%>', - 'cookie_flags': 'samesite=none;secure', - }); - ` - try { - const ejsRendered = ejs.render(js, req.app.locals) - return res.type('text/javascript').status(StatusCodes.OK).send(ejsRendered) - } catch (err) { - logger.error({ - message: 'Error returning datalayer', - meta: { - action: 'datalayer', - ...createReqMeta(req), - }, - error: err, - }) - return res.status(StatusCodes.BAD_REQUEST).json({ - message: 'There was an unexpected error. Please refresh and try again.', - }) - } +const reactFrontendPath = path.resolve('dist/frontend') +const reactHtml = readFileSync(path.join(reactFrontendPath, 'index.html'), { + encoding: 'utf8', +}) + +type MetaTags = { + title: string + description: string + image: string +} +const replaceWithMetaTags = ({ + title, + description, + image, +}: MetaTags): string => { + return reactHtml + .replace(/(__OG_TITLE__)/g, escape(title)) + .replace(/(__OG_DESCRIPTION__)/g, escape(description)) + .replace(/(__OG_IMAGE__)/g, escape(image)) } -/** - * Handler for GET /frontend/environment endpoint. - * @param req - Express request object - * @param res - Express response object - * @returns Templated Javascript code with environment variables for the frontend - */ -export const addEnvVarData: ControllerHandler = ( - req, - res, -) => { - try { - return res - .type('text/javascript') - .status(StatusCodes.OK) - .send(req.app.locals.environment) - } catch (err) { - logger.error({ - message: 'Error returning environment', - meta: { - action: 'environment', - ...createReqMeta(req), - }, - error: err, - }) - return res.status(StatusCodes.BAD_REQUEST).json({ - message: 'There was an unexpected error. Please refresh and try again.', - }) +const serveFormReact = + (isPublicForm: boolean): ControllerHandler => + async (req, res) => { + let tags: MetaTags = { + title: 'FormSG', + description: 'Trusted form manager of the Singapore Government', + image: 'og-img-metatag-nonpublicform.png', + } + + if (isPublicForm && get(req.params, 'formId')) { + tags = await getPublicFormMetaTags(get(req.params, 'formId') ?? '') + } + + const reactHtmlWithMetaTags = replaceWithMetaTags(tags) + + return ( + res + // Prevent index.html from being cached by browsers. + .setHeader('Cache-Control', 'no-cache') + .send(reactHtmlWithMetaTags) + ) } -} -/** - * Handler for GET /client/env endpoint. - * @returns the environment variables needed to hydrate the frontend. - */ -export const handleGetEnvironment: ControllerHandler = ( - _req, - res, -) => { - return res.json(getClientEnvVars()) -} +const getPublicFormMetaTags = async (formId: string): Promise => { + const createMetatagsResult = await createMetatags({ + formId, + }) -/** - * Handler for GET /frontend/redirect endpoint. - * @param req - Express request object - * @param res - Express response object - * @returns Templated Javascript code for the frontend that redirects to specific form url - */ -export const _generateRedirectUrl: ControllerHandler< - unknown, - string | { message: string }, - unknown, - { redirectPath: string } -> = (req, res) => { - const js = ` - // Update hash to match form id - window.location.hash = "#!/<%= redirectPath%>" - // Change url from form.gov.sg/123#!123 to form.gov.sg/#!/123 - window.history.replaceState("","", "/#!/<%= redirectPath%>") - ` - // If there are multiple query params, '&' is html-encoded as '&', which is not valid URI - // Prefer to replace just '&' instead of using <%- to output unescaped values into the template - // As this could potentially introduce security vulnerability - // See https://ejs.co/#docs for tags - try { - const ejsRendered = ejs.render(js, req.query).replace(/&/g, '&') - return res.type('text/javascript').status(StatusCodes.OK).send(ejsRendered) - } catch (err) { + if (createMetatagsResult.isErr()) { logger.error({ - message: 'Error returning redirectLayer', + message: 'Error fetching metatags', meta: { - action: 'redirectlayer', - ...createReqMeta(req), + action: 'getPublicFormMetaTags', + formId, }, - error: err, - }) - return res.status(StatusCodes.BAD_REQUEST).json({ - message: 'There was an unexpected error. Please refresh and try again.', + error: createMetatagsResult.error, }) + return { + title: 'FormSG', + description: '', + image: 'og-img-metatag-publicform.png', + } + } else { + const { title, description } = createMetatagsResult.value + return { + title: title, + description: description ?? '', + image: 'og-img-metatag-publicform.png', + } } } -export const generateRedirectUrl = [ - validateGenerateRedirectParams, - _generateRedirectUrl, -] as ControllerHandler[] +export const servePublicForm: ControllerHandler< + RedirectParams, + unknown, + unknown, + Record +> = async (req, res, next) => { + const formResult = await FormService.retrieveFormKeysById(req.params.formId, [ + 'responseMode', + 'status', + ]) -// Duplicated here since the feature manager is being deprecated. -// TODO (#2147): delete this. -enum FeatureNames { - Captcha = 'captcha', - GoogleAnalytics = 'google-analytics', - Sentry = 'sentry', - Sms = 'sms', - SpcpMyInfo = 'spcp-myinfo', - VerifiedFields = 'verified-fields', - WebhookVerifiedContent = 'webhook-verified-content', + const isPublicForm = + !formResult.isErr() && formResult.value.status === FormStatus.Public + + return serveFormReact(isPublicForm)(req, res, next) } -/** - * Handler for GET /frontend/features endpoint. - * @param _req - Express request object - * @param res - Express response object - * @returns Current featureManager states - * @deprecated as the feature manager has been deprecated. This endpoint - * now hardcodes the feature states to support old clients. - * TODO (#2147): delete this - */ -export const showFeaturesStates: ControllerHandler< - unknown, - Record -> = (_req, res) => { - return res.json({ - [FeatureNames.Captcha]: true, - [FeatureNames.Sms]: true, - [FeatureNames.SpcpMyInfo]: true, - [FeatureNames.VerifiedFields]: true, - [FeatureNames.GoogleAnalytics]: true, - [FeatureNames.WebhookVerifiedContent]: true, - [FeatureNames.Sentry]: true, - }) +export const serveDefault: ControllerHandler = (req, res, next) => { + return serveFormReact(/* isPublic= */ false)(req, res, next) } diff --git a/src/app/modules/frontend/frontend.routes.ts b/src/app/modules/frontend/frontend.routes.ts index 7f97568823..743b6973ec 100644 --- a/src/app/modules/frontend/frontend.routes.ts +++ b/src/app/modules/frontend/frontend.routes.ts @@ -1,47 +1,12 @@ import { Router } from 'express' -import * as FrontendServerController from './frontend.controller' +import * as FrontendController from './frontend.controller' -/** @deprecated use client router in src/app/routes/api/v3/client/client.routes.ts instead. */ export const FrontendRouter = Router() -/** - * @deprecated use routes in src/app/routes/api/v3/client/client.routes.ts instead - * Generate the templated Javascript code for the frontend to initialise Google Tag Manager - * Code depends on whether googleAnalyticsFeature.isEnabled - * @route GET /frontend/datalayer - * @return 200 when code generation is successful - * @return 400 when code generation fails - */ FrontendRouter.get( - '/datalayer', - FrontendServerController.addGoogleAnalyticsData, + '/:formId([a-fA-F0-9]{24})', + FrontendController.servePublicForm, ) -/** - * @deprecated use routes in src/app/routes/api/v3/client/client.routes.ts instead - * Generate the templated Javascript code with environment variables for the frontend - * @route GET /frontend/environment - * @return 200 when code generation is successful - * @return 400 when code generation fails - */ -FrontendRouter.get('/environment', FrontendServerController.addEnvVarData) - -/** - * @deprecated use routes in src/app/routes/api/v3/client/client.routes.ts instead - * Generate a json of current activated features - * @route GET /frontend/features - * @return json with featureManager.states - * @deprecated - * TODO (#2147): delete this - */ -FrontendRouter.get('/features', FrontendServerController.showFeaturesStates) - -/** - * @deprecated use routes in src/app/routes/api/v3/client/client.routes.ts instead - * Generate the javascript code to redirect to the correct url - * @route GET /frontend/redirect - * @return 200 when redirect code is successful - * @return 400 when redirect code fails - */ -FrontendRouter.get('/redirect', FrontendServerController.generateRedirectUrl) +FrontendRouter.get('*', FrontendController.serveDefault) diff --git a/src/app/modules/home/__tests__/home.controller.spec.ts b/src/app/modules/home/__tests__/home.controller.spec.ts deleted file mode 100644 index 8bb232377a..0000000000 --- a/src/app/modules/home/__tests__/home.controller.spec.ts +++ /dev/null @@ -1,19 +0,0 @@ -import * as HomeController from 'src/app/modules/home/home.controller' - -import expressHandler from 'tests/unit/backend/helpers/jest-express' - -describe('home.controller', () => { - describe('home', () => { - it('should render the home page without calling any downstream middleware', () => { - const mockReq = expressHandler.mockRequest() - const mockRes = expressHandler.mockResponse() - const mockNext = jest.fn() - - HomeController.home(mockReq, mockRes, mockNext) - - expect(mockRes.render).toHaveBeenCalledWith('index') - expect(mockRes.render).toHaveBeenCalledTimes(1) - expect(mockNext).not.toHaveBeenCalled() - }) - }) -}) diff --git a/src/app/modules/home/home.controller.ts b/src/app/modules/home/home.controller.ts deleted file mode 100644 index 25707fc25d..0000000000 --- a/src/app/modules/home/home.controller.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { ControllerHandler } from '../core/core.types' - -/** - * Renders the root page of the application. - * @param req - Express request object - * @param res - Express response object - */ -export const home: ControllerHandler = (_req, res) => { - return res.render('index') -} diff --git a/src/app/modules/home/home.routes.ts b/src/app/modules/home/home.routes.ts deleted file mode 100644 index 6ae06dbe13..0000000000 --- a/src/app/modules/home/home.routes.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { Router } from 'express' - -import * as HomeController from './home.controller' - -export const HomeRouter = Router() - -HomeRouter.get('/', HomeController.home) diff --git a/src/app/routes/api/v3/client/client.routes.ts b/src/app/routes/api/v3/client/client.routes.ts index 26d3907649..df35d9f09d 100644 --- a/src/app/routes/api/v3/client/client.routes.ts +++ b/src/app/routes/api/v3/client/client.routes.ts @@ -1,6 +1,6 @@ import { Router } from 'express' -import * as FrontendServerController from '../../../../modules/frontend/frontend.controller' +import * as FrontendServerController from '../../../../modules/frontend-old/frontend.controller' export const ClientRouter = Router()