UNPKG

@daiyu-5577/quickbuild

Version:

front-end build service

50 lines (49 loc) 2.01 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import express from 'express'; import path from 'path'; import { renderToPipeableStream } from 'react-dom/server'; import { baseRoute } from '../config.js'; const __dirname = new URL('.', import.meta.url).pathname; const staticPath = path.resolve(__dirname, '../../static'); import Home from '../../static/pages/home.js'; import Login from '../../static/pages/Login.js'; import Help from '../../static/pages/help.js'; const routes = [ { path: '/', component: Home }, { path: '/login', component: Login }, { path: '/help', component: Help } ]; const router = express.Router(); router.get(/.*/, (req, res) => { const curRoute = routes.find(route => route.path === req.path); if (!curRoute) { res.status(404).sendFile('pages/404.html', { root: staticPath }); return; } const { pipe } = renderToPipeableStream(_jsxs("html", { children: [_jsxs("head", { children: [_jsx("meta", { charSet: "utf-8" }), _jsx("meta", { name: "viewport", content: "width=device-width, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no,viewport-fit=cover" }), _jsx("title", { children: "quick build" }), _jsx("style", { children: ` html, body { margin: 0; padding: 0; min-height: 100vh; background: linear-gradient(135deg, #628ed0 0%, #c3e2d9 100%); } ` }), _jsx("script", { src: `${baseRoute}/static/pages/main.js` }), _jsx("script", { src: `${baseRoute}/static/pages/less@4.js` })] }), _jsx("body", { children: _jsx("div", { id: 'root', children: _jsx(curRoute.component, {}) }) })] }), { identifierPrefix: 'quick-build', bootstrapScripts: [], onShellReady() { res.setHeader('content-type', 'text/html'); pipe(res); } }); }); export default router;