You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
762 B
JavaScript
31 lines
762 B
JavaScript
import path from 'path'
|
|
import fs from 'fs/promises'
|
|
|
|
import { createServer as createViteServer } from 'vite'
|
|
import express from 'express'
|
|
|
|
const CONSTANTS = {
|
|
MODE_DEVELOPMENT: 'development',
|
|
}
|
|
|
|
async function createDevelopmentServer(app) {
|
|
const vite = await createViteServer({
|
|
server: { middlewareMode: true },
|
|
appType: 'custom',
|
|
})
|
|
|
|
app.use(vite.middlewares)
|
|
|
|
app.use('*', async (req, res) => {
|
|
// serve index.html
|
|
const indexHtml = await fs.readFile(path.resolve('./client/index.html'), 'utf-8')
|
|
const transformedIndexHtml = vite.transformIndexHtml(req.originalUrl, indexHtml)
|
|
})
|
|
}
|
|
|
|
function createProductionServer() {
|
|
app.use('/', express.static('client/dist'))
|
|
}
|
|
|
|
const app = express()
|