mirror of
https://github.com/aziis98/go-vite-kit.git
synced 2026-10-06 14:14:51 +00:00
fix: simplified development server architecture
This commit is contained in:
+3
-3
@@ -3,7 +3,7 @@ import express from 'express'
|
||||
import { createServer as createViteServer } from 'vite'
|
||||
import { readFile } from 'fs/promises'
|
||||
|
||||
import { getDevelopmentRoutes } from './routes.js'
|
||||
import { getBuildRoutes } from './routes.js'
|
||||
|
||||
async function createServer() {
|
||||
const app = express()
|
||||
@@ -14,9 +14,9 @@ async function createServer() {
|
||||
server: { middlewareMode: 'html' },
|
||||
})
|
||||
|
||||
const routes = await getDevelopmentRoutes()
|
||||
const routes = await getBuildRoutes()
|
||||
|
||||
console.log(`Mounting static routes:`)
|
||||
console.log(`mounting static routes...`)
|
||||
for (const [route, file] of Object.entries(routes)) {
|
||||
const filePath = join('./frontend', file)
|
||||
console.log(`- "%s" => %s`, route, filePath)
|
||||
|
||||
+2
-7
@@ -1,15 +1,9 @@
|
||||
import { spawn } from 'child_process'
|
||||
import axios from 'axios'
|
||||
|
||||
function transformRoutes(entrypoints) {
|
||||
return Object.fromEntries(entrypoints.map(({ route, filename }) => [route, filename]))
|
||||
}
|
||||
|
||||
export async function getDevelopmentRoutes() {
|
||||
const res = await axios.get('http://127.0.0.1:4000/dev/routes')
|
||||
return transformRoutes(res.data)
|
||||
}
|
||||
|
||||
export async function getBuildRoutes() {
|
||||
// Thanks to ChatGPT
|
||||
function readCommandOutputAsJSON(command) {
|
||||
@@ -40,5 +34,6 @@ export async function getBuildRoutes() {
|
||||
})
|
||||
}
|
||||
|
||||
return transformRoutes(await readCommandOutputAsJSON('go run ./cmd/routes'))
|
||||
console.log('loading build entrypoints...')
|
||||
return transformRoutes(await readCommandOutputAsJSON('go run ./meta/routes'))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"go-vite-kit/backend/routes"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
enc.SetIndent("", " ")
|
||||
if err := enc.Encode(routes.HtmlEntrypoints); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user