| 1 | import express from 'express'; |
| 2 | import cors from 'cors'; |
| 3 | import { createServer as createViteServer } from 'vite'; |
| 4 | import { packageOptions } from '../.build/common.js'; |
| 5 | |
| 6 | async function createServer() { |
| 7 | const app = express(); |
| 8 | const port = process.env.MERMAID_PORT ?? 9000; |
| 9 | |
| 10 | // Create Vite server in middleware mode |
| 11 | const vite = await createViteServer({ |
| 12 | configFile: './vite.config.ts', |
| 13 | mode: 'production', |
| 14 | server: { middlewareMode: true }, |
| 15 | appType: 'custom', // don't include Vite's default HTML handling middleware |
| 16 | }); |
| 17 | |
| 18 | app.use(cors()); |
| 19 | for (const { packageName } of Object.values(packageOptions)) { |
| 20 | app.use(express.static(`./packages/${packageName}/dist`)); |
| 21 | } |
| 22 | app.use(vite.middlewares); |
| 23 | app.use(express.static('demos')); |
| 24 | app.use(express.static('cypress/platform')); |
| 25 | |
| 26 | app.listen(port, () => { |
| 27 | // eslint-disable-next-line no-console |
| 28 | console.log(`Listening on http://localhost:${port}`); |
| 29 | }); |
| 30 | } |
| 31 | |
| 32 | void createServer(); |
| 33 | |