gosveltesveltekitmux

Serving static files recursively with go


I'm using sveltekit as my frontend for an app I'm working on. I've chosen a static adapter in the svelte.config.js which outputs all necessary components as static files. Here is the structure of my static directory. enter image description here

The upper most files load, however, files in static/_app do not

func main() {
    router := mux.NewRouter()
    router.Handle("/", http.FileServer(http.Dir("static")))
    router.HandleFunc("/large-files", largeFilesHandler).Methods("OPTIONS", "POST")
    router.HandleFunc("/delete-file", deleteFileHandler).Methods("DELETE", "OPTIONS")
    logrus.SetLevel(logrus.ErrorLevel)
    err := http.ListenAndServe(":8000", router)
    if err != nil {
        logrus.Fatal(err)
    }

}

And in my svelte.config.js

import adapter from '@sveltejs/adapter-static';
import preprocess from 'svelte-preprocess';

/** @type {import('@sveltejs/kit').Config} */
const config = {
    // Consult https://github.com/sveltejs/svelte-preprocess
    // for more information about preprocessors
    preprocess: preprocess(),
    kit: {
        adapter: adapter({
            pages: '../static',
            assets: '../static',
        })
        ,
        prerender: { default: true }
    }
};

export default config;

Update:

If I remove the html files, I get the directory list, but all of these options fail with a 404

enter image description here


Solution

  • mux handles static files differently.

        router.PathPrefix("/").Handler(http.FileServer(http.Dir("./static")))