const esbuild = require('esbuild'); const http = require('http'); const { iifeBuild, esmBuild } = require('./util.cjs'); const express = require('express'); // Start 2 esbuild servers. One for IIFE and one for ESM // Serve 2 static directories: demo & cypress/platform // Have 3 entry points: // mermaid: './src/mermaid', // e2e: './cypress/platform/viewer.js', // 'bundle-test': './cypress/platform/bundle-test.js', const getEntryPointsAndExtensions = (format) => { return { entryPoints: { mermaid: './src/mermaid', e2e: 'cypress/platform/viewer.js', 'bundle-test': 'cypress/platform/bundle-test.js', }, outExtension: { '.js': format === 'iife' ? '.js' : '.esm.mjs' }, }; }; const generateHandler = (server) => { return (req, res) => { const options = { hostname: server.host, port: server.port, path: req.url, method: req.method, headers: req.headers, }; // Forward each incoming request to esbuild const proxyReq = http.request(options, (proxyRes) => { // If esbuild returns "not found", send a custom 404 page if (proxyRes.statusCode === 404) { if (!req.url.endsWith('.html')) { res.writeHead(404, { 'Content-Type': 'text/html' }); res.end('