{"id":26953037,"url":"https://github.com/mateo08c/ginsvelteembed","last_synced_at":"2025-10-18T07:32:01.767Z","repository":{"id":269747233,"uuid":"908340572","full_name":"mateo08c/GinSvelteEmbed","owner":"mateo08c","description":"Embed SvelteKit frontend in a Go Gin Web Framework for seamless deployment.","archived":false,"fork":false,"pushed_at":"2025-04-02T22:02:08.000Z","size":499,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-02T22:28:18.195Z","etag":null,"topics":["amazing","demo","embed","framework","gin","gin-gonic","insane","svelte","sveltekit","tutorial"],"latest_commit_sha":null,"homepage":"https://gin-svelte-embed.mateo08.fr","language":"Svelte","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mateo08c.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-25T19:44:41.000Z","updated_at":"2025-04-02T22:02:11.000Z","dependencies_parsed_at":"2024-12-25T21:16:56.818Z","dependency_job_id":"30aa8683-82c5-4458-9459-418bf8be89e4","html_url":"https://github.com/mateo08c/GinSvelteEmbed","commit_stats":null,"previous_names":["mateo08c/ginsvelteembed"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mateo08c%2FGinSvelteEmbed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mateo08c%2FGinSvelteEmbed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mateo08c%2FGinSvelteEmbed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mateo08c%2FGinSvelteEmbed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mateo08c","download_url":"https://codeload.github.com/mateo08c/GinSvelteEmbed/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246917061,"owners_count":20854569,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amazing","demo","embed","framework","gin","gin-gonic","insane","svelte","sveltekit","tutorial"],"created_at":"2025-04-03T01:19:14.696Z","updated_at":"2025-10-18T07:31:56.714Z","avatar_url":"https://github.com/mateo08c.png","language":"Svelte","readme":"# 🚀 SvelteKit + Go: The Ultimate Full-Stack Boilerplate\n\nSupercharge your web development with this powerful combination of SvelteKit for the frontend and Go (with Gin) for the\nbackend. This boilerplate provides a seamless integration between these two cutting-edge technologies, allowing you to\nbuild scalable and performant web applications with ease.\n\n## ✨ Features\n\n- 🎨 **SvelteKit**: A powerful frontend framework for building blazing-fast web apps\n- 🚄 **Go + Gin**: High-performance backend with one of the fastest web frameworks for Go\n- 🔗 **Seamless Integration**: Pre-configured setup for smooth communication between frontend and backend\n- 🛠 **Development Ready**: Includes proxy configuration for easy local development\n- 📦 **Production Optimized**: Static adapter configuration for SvelteKit, ready for deployment\n\n## 🖥 Frontend Configuration (SvelteKit)\n\n### Static Adapter\n\nUpdate `svelte.config.js`:\n\n```js\nimport adapter from '@sveltejs/adapter-static';\nimport {vitePreprocess} from '@sveltejs/vite-plugin-svelte';\n\n/** @type {import('@sveltejs/kit').Config} */\nconst config = {\n    preprocess: vitePreprocess(),\n    kit: {\n        adapter: adapter({\n            pages: 'build',\n            assets: 'build',\n            fallback: 'index.html',\n            precompress: false\n        }),\n        prerender: {\n            handleHttpError: 'ignore'\n        }\n    }\n};\n\nexport default config;\n```\n\n### Disable SSR\n\nIn `src/routes/+layout.(js|ts)`:\n\n```js\nexport const ssr = false;\nexport const prerender = false;\n```\n\n### Go Integration\n\nCreate `web.go` in the root:\n\n```go\npackage web\n\nimport \"embed\"\n\n//go:embed build/*\nvar Fs embed.FS\n```\n\n## 🖥 Backend Configuration (Go)\n\n### Install Gin\n\nFirst, install the Gin web framework:\n\n```sh\ngo get -u github.com/gin-gonic/gin\n```\n\n### Example Usage\n\nCheck out `main.go` in the backend directory for an example of how to set up a basic Gin server and integrate it with\nthe SvelteKit frontend. Here's a snippet of what you might find:\n\n```go\npackage main\n\nimport (\n\t\"github.com/gin-gonic/gin\"\n\t\"io/fs\"\n\t\"log\"\n\t\"net/http\"\n\t\"package-name/web\"\n\t\"strings\"\n)\n\nfunc main() {\n\tf := getFileSystem()\n\n\t// Create a Gin engine\n\tr := gin.Default()\n\n\t// Define an API route\n\tapi := r.Group(\"/api\")\n\tapi.GET(\"/hello\", func(c *gin.Context) {\n\t\tc.JSON(http.StatusOK, gin.H{\"message\": \"Hello, world!\"})\n\t})\n\n\t// Serve static files and fallback for SPA\n\tr.Use(spaFileHandler(f))\n\n\t// Run the server on port 8080\n\tif err := r.Run(\":8080\"); err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n\nfunc spaFileHandler(httpFS http.FileSystem) gin.HandlerFunc {\n\tfileServer := http.FileServer(httpFS)\n\treturn func(c *gin.Context) {\n\t\tpath := c.Request.URL.Path\n\n\t\t// Bypass the handler for API requests\n\t\tif strings.HasPrefix(path, \"/api\") {\n\t\t\tc.Next()\n\t\t\treturn\n\t\t}\n\n\t\t// Try to serve the exact file\n\t\tif _, err := httpFS.Open(path); err == nil {\n\t\t\tfileServer.ServeHTTP(c.Writer, c.Request)\n\t\t\treturn\n\t\t}\n\n\t\t// Fallback to serving index.html for SPA\n\t\tc.Request.URL.Path = \"/\"\n\t\tfileServer.ServeHTTP(c.Writer, c.Request)\n\t\tc.Request.URL.Path = path // Restore the original path\n\t}\n}\n\n// getFileSystem retrieves the embedded filesystem for serving static files\nfunc getFileSystem() http.FileSystem {\n\tfSys, err := fs.Sub(web.Fs, \"build\") // Extract the \"build\" directory from the embedded filesystem\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn http.FS(fSys)\n}\n\n```\n\n## 🛠 Development\n\nFor local development, update `vite.config.js` to proxy API requests:\n\n```js\nimport {sveltekit} from '@sveltejs/kit/vite';\nimport {defineConfig} from 'vite';\n\nexport default defineConfig({\n    plugins: [sveltekit()],\n    server: {\n        proxy: {\n            \"/api\": {\n                target: \"http://127.0.0.1:8080\",\n                changeOrigin: true,\n                secure: false,\n                ws: true,\n            },\n        },\n    },\n});\n```\n\n## ⚠️ Important Note\n\nBefore running the Go server, make sure to build the SvelteKit frontend or create empty directories for the static files:\n\n```sh\nnpm run build\n```\n\n## 📚 Learn More\n\n- [SvelteKit Documentation](https://kit.svelte.dev/docs)\n- [Go Documentation](https://golang.org/doc/)\n- [Gin Web Framework](https://gin-gonic.com/docs/)\n\n## 🤝 Contributing\n\nContributions, issues, and feature requests are welcome! Feel free to check [issues page](link-to-issues).\n\n---\n\nHappy coding! 🎉","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmateo08c%2Fginsvelteembed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmateo08c%2Fginsvelteembed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmateo08c%2Fginsvelteembed/lists"}