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

main
Antonio De Lucreziis 2 years ago
parent 2d1ecedcf0
commit 0481510065

3
.gitignore vendored

@ -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,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: {

Loading…
Cancel
Save