Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: PublicRuntimeEnvironment not available in docker #661

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:12-alpine
FROM node:lts-alpine
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated node


RUN apk add --update bash

Expand All @@ -12,6 +12,9 @@ RUN npm install
# Copying source files
COPY . .

# Remove Env variables from container before building
RUN rm -rf .env

Comment on lines +15 to +17
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing .env from the docker image during build process. This is to prevent local .env during development from being used for publicRuntimeConfig

# Give permission to run script
RUN chmod +x ./wait-for-it.sh

Expand Down
7 changes: 2 additions & 5 deletions client/consts/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import getConfig from "next/config";

const { publicRuntimeConfig } = getConfig();

export const DISALLOW_ANONYMOUS_LINKS =
publicRuntimeConfig.DISALLOW_ANONYMOUS_LINKS === "true";

export const DISALLOW_REGISTRATION =
publicRuntimeConfig.DISALLOW_REGISTRATION === "true";
export const { DISALLOW_ANONYMOUS_LINKS } = publicRuntimeConfig;
export const { DISALLOW_REGISTRATION } = publicRuntimeConfig;

export enum APIv2 {
AuthLogin = "/api/v2/auth/login",
Expand Down
2 changes: 2 additions & 0 deletions client/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export type { PublicRuntimeConfig } from "../server/env";

export interface TokenPayload {
iss: "ApiAuth";
sub: string;
Expand Down
12 changes: 12 additions & 0 deletions server/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,16 @@ const env = cleanEnv(process.env, {
CONTACT_EMAIL: str({ default: "" })
});

export const publicRuntimeConfig = {
x: 3,
CONTACT_EMAIL: env?.CONTACT_EMAIL,
SITE_NAME: env?.SITE_NAME,
DEFAULT_DOMAIN: env?.DEFAULT_DOMAIN,
RECAPTCHA_SITE_KEY: env?.RECAPTCHA_SITE_KEY,
REPORT_EMAIL: env?.REPORT_EMAIL,
DISALLOW_ANONYMOUS_LINKS: env.DISALLOW_ANONYMOUS_LINKS,
DISALLOW_REGISTRATION: env?.DISALLOW_REGISTRATION
};

export type PublicRuntimeConfig = typeof publicRuntimeConfig;
export default env;
8 changes: 6 additions & 2 deletions server/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import env from "./env";
import env, { publicRuntimeConfig } from "./env";

import asyncHandler from "express-async-handler";
import cookieParser from "cookie-parser";
Expand All @@ -18,7 +18,11 @@ import "./cron";
import "./passport";

const port = env.PORT;
const app = nextApp({ dir: "./client", dev: env.isDev });
const app = nextApp({
dir: "./client",
dev: env.isDev,
conf: { publicRuntimeConfig }
Copy link
Author

@dkyeremeh dkyeremeh Dec 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add publicRuntimeConfig to nextApp from express

});
const handle = app.getRequestHandler();

app.prepare().then(async () => {
Expand Down