diff --git a/docker-compose.yml b/docker-compose.yml index 065ab61ce2..36a1673968 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,6 +20,7 @@ services: - DB_HOST=mongodb://database:27017/formsg - APP_NAME=FormSG - APP_URL=http://localhost:5001 + - FE_APP_URL=http://localhost:3000 - ATTACHMENT_S3_BUCKET=local-attachment-bucket - IMAGE_S3_BUCKET=local-image-bucket - LOGO_S3_BUCKET=local-logo-bucket diff --git a/src/app/config/schema.ts b/src/app/config/schema.ts index 5faca2694b..a8e9011b69 100644 --- a/src/app/config/schema.ts +++ b/src/app/config/schema.ts @@ -150,6 +150,12 @@ export const optionalVarsSchema: Schema = { default: 'https://form.gov.sg', env: 'APP_URL', }, + feAppUrl: { + doc: 'For local dev use only - frontend app url', + format: 'url', + default: 'https://form.gov.sg', + env: 'FE_APP_URL', + }, keywords: { doc: 'Application keywords in meta tag', format: String, diff --git a/src/app/modules/myinfo/myinfo.controller.ts b/src/app/modules/myinfo/myinfo.controller.ts index e1e5a63939..928ab1a22d 100644 --- a/src/app/modules/myinfo/myinfo.controller.ts +++ b/src/app/modules/myinfo/myinfo.controller.ts @@ -1,6 +1,8 @@ import { celebrate, Joi, Segments } from 'celebrate' import { StatusCodes } from 'http-status-codes' +import { Environment } from '../../../types' +import config from '../../config/config' import { createLoggerWithLabel } from '../../config/logger' import { createReqMeta } from '../../utils/request' import { ControllerHandler } from '../core/core.types' @@ -139,11 +141,17 @@ export const loginToMyInfo: ControllerHandler< } const { formId, encodedQuery } = parseStateResult.value - let redirectDestination = `/${formId}` + // For local dev, we need to specify the frontend app URL as this is different from the backend's app URL + const redirectDestinationRaw = + process.env.NODE_ENV === Environment.Dev + ? `${config.app.feAppUrl}/${formId}` + : `/${formId}` + + let redirectDestination = redirectDestinationRaw if (encodedQuery) { try { - redirectDestination = `/${formId}?${Buffer.from( + redirectDestination = `${redirectDestinationRaw}?${Buffer.from( encodedQuery, 'base64', ).toString('utf8')}` diff --git a/src/types/config.ts b/src/types/config.ts index 663301cc21..eea6ee5069 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -16,6 +16,7 @@ export type AppConfig = { title: string description: string appUrl: string + feAppUrl: string keywords: string images: string[] twitterImage: string