2

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

Brandon Kauffman
  • 1,515
  • 1
  • 7
  • 33

1 Answers1

2

mux handles static files differently.

    router.PathPrefix("/").Handler(http.FileServer(http.Dir("./static")))
Brandon Kauffman
  • 1,515
  • 1
  • 7
  • 33
  • 1
    It's not that it handles static files differently (it's a handler, exactly like any other), it's that in Gorilla mux, `Handle`/`HandleFunc` are exact pattern matches. You have to use `PathPrefix` to match a path prefix like this (hence the name). – Adrian Aug 26 '22 at 13:51