8000 Add support for Next `basePath` · Issue #416 · opennextjs/opennextjs-cloudflare · GitHub
[go: up one dir, main page]

Skip to content
8000

Add support for Next basePath #416

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

Closed
vicb opened this issue Feb 26, 2025 · 2 comments · Fixed by #574
Closed

Add support for Next basePath #416

vicb opened this issue Feb 26, 2025 · 2 comments · Fixed by #574

Comments

@vicb
Copy link
Contributor
vicb commented Feb 26, 2025

When using a basePath:

/** @type {import('next').NextConfig} */
const nextConfig = {
  basePath: "/test",
};

export default nextConfig;

Static assets and images are not handled correctly:

[wrangler:inf] GET /test/_next/static/chunks/37-312626403a8d5b54.js 404 Not Found (26ms)
[wrangler:inf] GET /test/_next/image 404 Not Found (24ms)
[wrangler:inf] GET /test/_next/static/chunks/app/posts/%5Bslug%5D/page-ae483e7dadc24cd7.js 404 Not Found (27ms)
@pliashkou
Copy link

Please, prioritize higher.

@juanferreras
Copy link

in case it unblocks anyone – haven't fully tested it but seems like a very fragile and temporary post-build workaround like the following makes it work OK both locally built and deployed. TBC if anything does not work as expected (I'd assume images would definitely not 9868 work, likely some of the added cache functionality, etc.)

still was helpful to get static assets chunks (css/js/fonts) resolving instead of 404ing

#!/bin/sh

set -e  # Exit on any error

# Configuration
BASE_PATH_DIR="basepath"
SOURCE_DIR=".open-next/assets"
DEST_DIR="${SOURCE_DIR}/${BASE_PATH_DIR}"

# Create destination directory
mkdir -p "${DEST_DIR}" || { echo "Failed to create destination directory"; exit 1; }

# Move all contents (including hidden files) to the destination
mv "${SOURCE_DIR}"/* "${SOURCE_DIR}"/.??* "${DEST_DIR}/" 2>/dev/null || true

echo "┌────────────────────────────────────────────────────────────────────────────┐"
echo "│ [patch] basePath patched: /assets/ moved successfully to /assets/basePath/ │"
echo "└────────────────────────────────────────────────────────────────────────────┘"

(run chmod +x _fix-base-path.sh once to make it executable)

you can then edit your build/deploy scripts so this always run after "build": "opennextjs-cloudflare && ./_fix-base-path.sh",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0