server.js — vite Source File
Architecture documentation for server.js, a javascript file in the vite codebase. 3 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR a3d84c64_915f_7330_2056_f4c872e19179["server.js"] e6032fbc_44cf_58d6_868d_dd15106c18c5["node:fs"] a3d84c64_915f_7330_2056_f4c872e19179 --> e6032fbc_44cf_58d6_868d_dd15106c18c5 51e96894_3556_ed5c_1ede_97d449867adf["node:path"] a3d84c64_915f_7330_2056_f4c872e19179 --> 51e96894_3556_ed5c_1ede_97d449867adf c7183a98_0eee_01f4_23b4_5554e5d0e216["express"] a3d84c64_915f_7330_2056_f4c872e19179 --> c7183a98_0eee_01f4_23b4_5554e5d0e216 style a3d84c64_915f_7330_2056_f4c872e19179 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import fs from 'node:fs'
import path from 'node:path'
import express from 'express'
const isTest = process.env.VITEST
export async function createServer(
root = process.cwd(),
hmrPort,
customLogger,
) {
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',
customLogger,
})
// use vite's connect instance as middleware
app.use(vite.middlewares)
app.use('*all', async (req, res, next) => {
try {
const url = req.originalUrl
let template
template = fs.readFileSync(resolve('index.html'), 'utf-8')
template = await vite.transformIndexHtml(url, template)
const render = (await vite.ssrLoadModule('/src/app.js')).render
const appHtml = await render(url, import.meta.dirname)
const html = template.replace(`<!--app-html-->`, appHtml)
res.status(200).set({ 'Content-Type': 'text/html' }).end(html)
} catch (e) {
vite && vite.ssrFixStacktrace(e)
if (isTest) throw e
console.log(e.stack)
res.status(500).end(e.stack)
}
})
return { app, vite }
}
if (!isTest) {
createServer().then(({ app }) =>
app.listen(5173, () => {
console.log('http://localhost:5173')
}),
)
}
Domain
Subdomains
Functions
Dependencies
- express
- node:fs
- node:path
Source
Frequently Asked Questions
What does server.js do?
server.js is a source file in the vite codebase, written in javascript. It belongs to the ViteCore domain, DevServer subdomain.
What functions are defined in server.js?
server.js defines 1 function(s): createServer.
What does server.js depend on?
server.js imports 3 module(s): express, node:fs, node:path.
Where is server.js in the architecture?
server.js is located at playground/ssr/server.js (domain: ViteCore, subdomain: DevServer, directory: playground/ssr).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free