From c1e791bad0b079af67398f6407221e6dcbb573dd Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Wed, 25 Jul 2018 22:01:25 +0200 Subject: expliciting type checks and predicates (server only) --- server/lib/redis.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'server/lib/redis.ts') diff --git a/server/lib/redis.ts b/server/lib/redis.ts index 06a340060..e547537c3 100644 --- a/server/lib/redis.ts +++ b/server/lib/redis.ts @@ -6,8 +6,8 @@ import { CONFIG, USER_PASSWORD_RESET_LIFETIME, VIDEO_VIEW_LIFETIME } from '../in type CachedRoute = { body: string, - contentType?: string - statusCode?: string + contentType: string + statusCode: string } class Redis { @@ -75,11 +75,12 @@ class Redis { } setCachedRoute (req: express.Request, body: any, lifetime: number, contentType?: string, statusCode?: number) { - const cached: CachedRoute = { - body: body.toString(), - contentType, - statusCode: statusCode.toString() - } + const cached: CachedRoute = Object.assign({}, { + body: body.toString() + }, + (contentType) ? { contentType } : null, + (statusCode) ? { statusCode: statusCode.toString() } : null + ) return this.setObject(this.buildCachedRouteKey(req), cached, lifetime) } -- cgit v1.2.3