Skip to content

Commit

Permalink
Fix base path vars and Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
mpgxvii committed Oct 11, 2024
1 parent b8e4e7a commit c9040f8
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 11 deletions.
37 changes: 33 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
node_modules/
.github/
.idea/
.vscode/
# Node modules
node_modules
npm-debug.log

# Build artifacts
.next
out

# Local environment files
.env

# Logs
logs
*.log

# IDE and editor files
.vscode
.idea
*.swp
*.swo

# Operating system files
.DS_Store
Thumbs.db

# Git files
.git
.gitignore

# Other files you may want to ignore
coverage
test-results
*.tgz
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ ENV NPM_CONFIG_CACHE=/home/node/.npm

COPY package*.json ./

RUN mkdir -p $NPM_CONFIG_CACHE && chown -R node:node $NPM_CONFIG_CACHE

RUN npm install

COPY . .

RUN npm run build
RUN npm run build

# Copy the env substitution script and ensure it is executable
COPY docker/30-env-subst.sh /docker-entrypoint.d/30-env-subst.sh
RUN chmod +x /docker-entrypoint.d/30-env-subst.sh

ENTRYPOINT ["/bin/sh", "-c", "/docker-entrypoint.d/30-env-subst.sh && exec \"$@\"", "--"]

EXPOSE 3000

Expand Down
19 changes: 19 additions & 0 deletions docker/30-env-subst.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

# Log that the script is running
echo "Running docker-entrypoint.sh."

# Replace placeholder with actual environment variable values
if [ -n "$BASE_PATH" ]; then
echo "Replacing BASE_PATH in env.template.js with ${BASE_PATH}"
sed -i "s|/__BASE_PATH__|${BASE_PATH}|g" /app/env.js
else
echo "BASE_PATH is not set."
fi

# Log the contents of env.template.js after modification
echo "Contents of env.template.js after replacement:"
cat /app/env.js

# Start the application
echo "Starting the application..."
3 changes: 3 additions & 0 deletions env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
basePath: "/kratos-ui"
}
13 changes: 10 additions & 3 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
/** @type {import('next').NextConfig} */
const envConfig = require("./env.js") // Load the generated config

module.exports = {
reactStrictMode: true,
basePath: process.env.BASE_PATH || "",
assetPrefix: process.env.BASE_PATH ?? "" + "/",

// Set basePath and assetPrefix dynamically
basePath: envConfig.basePath || "",
assetPrefix: `${envConfig.basePath}/` || "",

publicRuntimeConfig: {
basePath: envConfig.basePath || "",
},
}
6 changes: 5 additions & 1 deletion pkg/sdk/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Configuration, FrontendApi } from "@ory/client"
import { edgeConfig } from "@ory/integrations/next"
import getConfig from "next/config"

const { publicRuntimeConfig } = getConfig()
const { basePath } = publicRuntimeConfig

const localConfig = {
basePath: `${process.env.NEXT_PUBLIC_KRATOS_PUBLIC_URL}/api/.ory`,
basePath: `${basePath}/api/.ory`,
baseOptions: {
withCredentials: true,
},
Expand Down

0 comments on commit c9040f8

Please sign in to comment.