mirror of
https://github.com/aziis98/go-vite-kit.git
synced 2026-10-06 22:24:52 +00:00
Added a routes.js file for writing routes and entry html files only once
This commit is contained in:
+2
-1
@@ -1,7 +1,8 @@
|
||||
# NodeJS
|
||||
node_modules/
|
||||
dist/
|
||||
|
||||
# Server
|
||||
# Server Executable
|
||||
server
|
||||
|
||||
# Local Files
|
||||
|
||||
@@ -15,9 +15,11 @@ Minimal boilerplate project for a Golang server using [Fiber](https://github.com
|
||||
|
||||
This is a Vite project for building all the static pages used by this app.
|
||||
|
||||
The `routes.js` (this is used both from `server.js` for _serving_ and from `vite.config.js` for _building_) file contains a mapping from express route patterns to entry html files, this is useful for rendering the same page for multiple urls in development mode.
|
||||
|
||||
- `database/`
|
||||
|
||||
Module with a `Database` interface and two implementation: `memDB` is an in-memory database for testing purposes while `sqliteDB` is a wrapper for working with an SQLite database.
|
||||
Module with a `Database` interface and two implementation: `memDB` is an in-memory database for testing purposes. `sqliteDB` is a wrapper for working with an SQLite database.
|
||||
|
||||
- `routes/`
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export default {
|
||||
'/': './index.html',
|
||||
}
|
||||
+3
-4
@@ -3,6 +3,8 @@ import express from 'express'
|
||||
import { createServer as createViteServer } from 'vite'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import routes from './routes.js'
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
async function createServer(customHtmlRoutes) {
|
||||
@@ -28,7 +30,4 @@ async function createServer(customHtmlRoutes) {
|
||||
app.listen(3000)
|
||||
}
|
||||
|
||||
createServer({
|
||||
// Useful for developing with dynamic routes
|
||||
'/': './index.html',
|
||||
})
|
||||
createServer(routes)
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
import { basename } from 'path'
|
||||
import { defineConfig } from 'vite'
|
||||
|
||||
// Routes
|
||||
import routes from './routes.js'
|
||||
|
||||
const entryPoints = Object.fromEntries(
|
||||
Object.values(routes).map(path => [basename(path, '.html'), path])
|
||||
)
|
||||
|
||||
export default defineConfig({
|
||||
build: {
|
||||
rollupOptions: {
|
||||
input: {
|
||||
'/index': 'index.html',
|
||||
},
|
||||
input: entryPoints,
|
||||
},
|
||||
},
|
||||
server: {
|
||||
|
||||
Reference in New Issue
Block a user