Added a routes.js file for writing routes and entry html files only once

This commit is contained in:
2022-07-01 02:03:29 +02:00
parent 2d1ecedcf0
commit 0481510065
5 changed files with 20 additions and 9 deletions
+2 -1
View File
@@ -1,7 +1,8 @@
# NodeJS
node_modules/
dist/
# Server
# Server Executable
server
# Local Files
+3 -1
View File
@@ -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/`
+3
View File
@@ -0,0 +1,3 @@
export default {
'/': './index.html',
}
+3 -4
View File
@@ -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)
+9 -3
View File
@@ -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: {