Home / Function/ createServer() — tailwindcss Function Reference

createServer() — tailwindcss Function Reference

Architecture documentation for the createServer() function in ui.spec.ts from the tailwindcss codebase.

Entity Profile

Relationship Graph

Source Code

packages/@tailwindcss-browser/tests/ui.spec.ts lines 104–171

async function createServer() {
  const { createApp, createRouter, defineEventHandler, toNodeListener } = await import('h3')
  const { listen } = await import('listhen')

  interface PageOptions {
    page: Page
    head?: string
    body?: string
    htmlClasses?: string
  }

  async function render({ page, htmlClasses, head, body }: PageOptions) {
    let content = html`
      <!doctype html>
      <html lang="en" class="${htmlClasses ?? ''}">
        <head>
          <meta charset="UTF-8" />
          <meta http-equiv="X-UA-Compatible" content="IE=edge" />
          <meta name="viewport" content="width=device-width, initial-scale=1.0" />
          <title>Document</title>
          <script src="/tailwindcss.js"></script>
          <style type="text/tailwindcss">
            @theme {
              --color-red: #ff0000;
              --color-green: #00ff00;
              --color-blue: #0000ff;
            }
          </style>
          ${head ?? ''}
        </head>
        <body>
          ${body ?? ''}
        </body>
      </html>
    `

    router.get(
      '/',
      defineEventHandler(() => content),
    )

    await page.goto(server.url)
  }

  const app = createApp()
  const router = createRouter()

  router.get(
    '/tailwindcss.js',
    defineEventHandler(() => readFile(require.resolve('@tailwindcss/browser'))),
  )

  app.use(router)

  let workerIndex = Number(process.env.TEST_WORKER_INDEX ?? 0)

  let listener = await listen(toNodeListener(app), {
    port: 3000 + workerIndex,
    showURL: false,
    open: false,
  })

  return {
    app,
    url: listener.url,
    render,
  }
}

Domain

Subdomains

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free