Skip to content

infinite redirect when serving from a subfolder with adapter-static #12736

Closed as not planned
@xucian

Description

@xucian

Describe the bug

I have django for backend and (trying to have) svelte on the frontend.
I'm serving the static output of sveltekit via django & whitenoise (but I can also reproduce it with a simple python server, so it's not about django).

in django, I'm returning index.html for any path that doesn't exist:
urls.py

    re_path(r'^(?!static/).*$', serve, {
        'document_root': settings.STATIC_ROOT,
        'path': 'spa/index.html'
    }),

this works fine with an angular-based front-end (using ng build --base-href=/static/spa/) , but svelte is just stuck in a redirect loop no matter what I try.

I'm doing everything I've found in docs. the initial load correctly finds all the js files and the index.html, but it just shows a white page and it infinitely redirects to something -- I can't quite debug it as it's happening really fast.

svelte.config.js

// import adapterAuto from '@sveltejs/adapter-auto';
import adapterStatic from '@sveltejs/adapter-static';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
const config = {
	// Consult https://kit.svelte.dev/docs/integrations#preprocessors
	// for more information about preprocessors
	preprocess: vitePreprocess(),

	kit: {
		adapter: adapterStatic({
			fallback: 'index.html', // SPA mode // may differ from host to host

			pages: "../.frontend-dist",
		}),
		prerender: {
			entries: []
		},
		paths: {
			base: "/static/spa",
		}
	},
};

export default config;

any help is appreciated

Reproduction

I'm sure this is immediately obvious to maintainers. please just go over my message and I'm sure you'll know why it happens, it's probably a hidden config I'm missing that I'm not aware of

Logs

No response

System Info

System:
    OS: macOS 14.6.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 161.69 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.1 - ~/.nvm/versions/node/v18.16.1/bin/node
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.1/bin/npm
  Browsers:
    Chrome: 129.0.6668.60
    Safari: 17.6

Severity

blocking all usage of SvelteKit

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions