pixelmund / svemix

The Full-Stack addition to SvelteKit. Write your server code inside svelte files, handle sessions, forms and SEO easily.
https://svemix.com
MIT License
337 stars 16 forks source link

Internal Server Error 500 If `kit.config.trailingSlash: "always"` #28

Closed Acmion closed 2 years ago

Acmion commented 2 years ago

In SvelteKit one can configure whether routes should or should not have a trailing slash and this has relevance when it comes to relative urls. However, Svemix will throw an error if kit.config.trailingSlash: "always".

This config will work:

import adapter from '@sveltejs/adapter-auto';
import preprocess from 'svelte-preprocess';
import svemix from 'svemix/plugin';

/** @type {import('@sveltejs/kit').Config} */
const config = {
    preprocess: preprocess(),
    kit: {
        adapter: adapter(),
        target: '#svelte',
        vite: 
        {
            plugins: [svemix()]
        }
    }
};

export default config;

But this will not:

import adapter from '@sveltejs/adapter-auto';
import preprocess from 'svelte-preprocess';
import svemix from 'svemix/plugin';

/** @type {import('@sveltejs/kit').Config} */
const config = {
    preprocess: preprocess(),
    kit: {
        adapter: adapter(),
        target: '#svelte',
        vite: 
        {
            plugins: [svemix()]
        },
        trailingSlash: "always" // this line is the problem
    }
};

export default config;

To test this, remember to delete the $__svemix__ directories after changing the config.

The error that one gets is An unknown error occured, which originates from load.ts.

I do not know for sure why this happens, but I have two speculative theories:

  1. There is some string.split("/") action going on somewhere.
  2. The kit.config.trailingSlash option messes with the generated Svemix files. In other words, when kit.config.trailingSlash: "always" one should search for the appropriate endpoint from a different location. This has most likely something to do with the endpoint index.ts files.

Explanation number two seems more probable, but I do not know for sure.

pixelmund commented 2 years ago

Closed by #31