Skip to content

Commit

Permalink
fix: render 404 page even on non-existent pages in /api (#240)
Browse files Browse the repository at this point in the history
* fix: non existant pages on /api sends 404

* refactor: move shared constant to constants.ts
  • Loading branch information
JasonChong96 authored Jul 1, 2020
1 parent bdc38f8 commit 9257bd7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/server/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Express from 'express'
import jsonMessage from '../util/json'
import { ERROR_404_PATH } from '../constants'

const router = Express.Router()

Expand Down Expand Up @@ -47,4 +48,8 @@ router.use('/user', userGuard, preprocess, require('./user'))
router.use('/qrcode', userGuard, require('./qrcode'))
router.use('/link-stats', userGuard, require('./link-statistics'))

router.use((_, res) => {
res.status(404).render(ERROR_404_PATH)
})

export default router
2 changes: 1 addition & 1 deletion src/server/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ export const DependencyIds = {
deviceCheckService: Symbol.for('deviceCheckService'),
}

export default DependencyIds
export const ERROR_404_PATH = '404.error.ejs'
3 changes: 1 addition & 2 deletions src/server/controllers/RedirectController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { inject, injectable } from 'inversify'
import { gaTrackingId, logger } from '../config'
import { NotFoundError } from '../util/error'
import parseDomain from '../util/domain'
import { DependencyIds } from '../constants'
import { DependencyIds, ERROR_404_PATH } from '../constants'
import { AnalyticsLogger } from '../services/analyticsLogger'
import { RedirectControllerInterface } from './interfaces/RedirectControllerInterface'
import { RedirectService } from '../services/RedirectService'
Expand All @@ -13,7 +13,6 @@ import {
EventCategory,
} from '../services/googleAnalytics/types/enum'

const ERROR_404_PATH = '404.error.ejs'
const TRANSITION_PATH = 'transition-page.ejs'

@injectable()
Expand Down
7 changes: 4 additions & 3 deletions src/server/views/404.error.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
<meta http-equiv="Content-Language" content="en">
<meta charset="UTF-8">
<title>Go.gov.sg: Page not found</title>
<base href="~/" />
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;700&display=swap" rel="stylesheet">
<link href="./assets/not-found-page/styles/not-found-page.css" rel="stylesheet">
<link href="/assets/not-found-page/styles/not-found-page.css" rel="stylesheet">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
</head>

Expand All @@ -23,11 +24,11 @@
<div id="divider" class="divider"></div>
<div id="graphics-container">
<div id="graphic-div">
<img src="./assets/not-found-page/images/not-found-graphic.svg" draggable="false" />
<img src="/assets/not-found-page/images/not-found-graphic.svg" draggable="false" />
</div>
<div id="go-logo-div">
<!-- go logo -->
<img src="./assets/not-found-page/icons/go-logo.svg" draggable="false" />
<img src="/assets/not-found-page/icons/go-logo.svg" draggable="false" />
</div>
</div>
</main>
Expand Down

0 comments on commit 9257bd7

Please sign in to comment.