refactor: implement script tag approach for library inclusion
- Add script tags to demo-site HTML files for manual development - Disable CLI inline script injection to prevent duplicate scripts - Add library serving endpoints to servedev command - Update build process to auto-copy library to demo-site - Add CDN URL helpers for future production deployment - Update .gitignore for generated demo-site files Fixes .insertr-gate authentication for manual npm run serve workflow while maintaining clean separation between CLI and manual setups.
This commit is contained in:
@@ -80,6 +80,12 @@ func runServedev(cmd *cobra.Command, args []string) {
|
||||
serveEditorAsset(w, r, assetPath)
|
||||
})
|
||||
|
||||
// Handle insertr library files
|
||||
http.HandleFunc("/insertr/", func(w http.ResponseWriter, r *http.Request) {
|
||||
assetPath := strings.TrimPrefix(r.URL.Path, "/insertr/")
|
||||
serveLibraryAsset(w, r, assetPath)
|
||||
})
|
||||
|
||||
// Handle all other requests with our enhanced file server
|
||||
http.Handle("/", fileServer)
|
||||
|
||||
@@ -120,6 +126,24 @@ func serveEditorAsset(w http.ResponseWriter, r *http.Request, assetPath string)
|
||||
http.ServeFile(w, r, assetFile)
|
||||
}
|
||||
|
||||
// serveLibraryAsset serves the insertr library files from embedded assets
|
||||
func serveLibraryAsset(w http.ResponseWriter, r *http.Request, assetPath string) {
|
||||
w.Header().Set("Content-Type", "application/javascript")
|
||||
|
||||
var script string
|
||||
switch assetPath {
|
||||
case "insertr.js":
|
||||
script = content.GetLibraryScript(false)
|
||||
case "insertr.min.js":
|
||||
script = content.GetLibraryScript(true)
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(script))
|
||||
}
|
||||
|
||||
// enhancedFileSystem wraps http.FileSystem to provide enhanced HTML serving
|
||||
type enhancedFileSystem struct {
|
||||
fs http.FileSystem
|
||||
|
||||
Reference in New Issue
Block a user