createServer() — vite Function Reference
Architecture documentation for the createServer() function in server.js from the vite codebase.
Entity Profile
Dependency Diagram
graph TD d19bfc0e_d0af_9645_135c_a6b1a89492b7["createServer()"] 58806f63_238c_34cc_f316_a3485466a67f["server.js"] d19bfc0e_d0af_9645_135c_a6b1a89492b7 -->|defined in| 58806f63_238c_34cc_f316_a3485466a67f style d19bfc0e_d0af_9645_135c_a6b1a89492b7 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
playground/ssr-pug/server.js lines 17–67
export async function createServer(root = process.cwd(), hmrPort) {
const resolve = (p) => path.resolve(import.meta.dirname, p)
const app = express()
/**
* @type {import('vite').ViteDevServer}
*/
const vite = await (
await import('vite')
).createServer({
root,
logLevel: isTest ? 'error' : 'info',
server: {
middlewareMode: true,
watch: {
// During tests we edit the files too fast and sometimes chokidar
// misses change events, so enforce polling for consistency
usePolling: true,
interval: 100,
},
hmr: {
port: hmrPort,
},
},
appType: 'custom',
})
// use vite's connect instance as middleware
app.use(vite.middlewares)
app.use('*all', async (req, res) => {
try {
let [url] = req.originalUrl.split('?')
url = url.replace(/\.html$/, '.pug')
if (url.endsWith('/')) url += 'index.pug'
const htmlLoc = resolve(`.${url}`)
let html = pug.renderFile(htmlLoc)
html = html.replace('</body>', `${DYNAMIC_SCRIPTS}</body>`)
html = await vite.transformIndexHtml(url, html)
res.status(200).set({ 'Content-Type': 'text/html' }).end(html)
} catch (e) {
vite && vite.ssrFixStacktrace(e)
console.log(e.stack)
res.status(500).end(e.stack)
}
})
return { app, vite }
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does createServer() do?
createServer() is a function in the vite codebase, defined in playground/ssr-pug/server.js.
Where is createServer() defined?
createServer() is defined in playground/ssr-pug/server.js at line 17.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free