2022-10-17 14:01:44 +05:30
|
|
|
import express, { NextFunction, Request, Response } from 'express';
|
2022-09-23 10:56:39 +05:30
|
|
|
import { createServer as createViteServer } from 'vite';
|
2022-09-22 15:35:22 +05:30
|
|
|
// import { getBuildConfig } from './build';
|
|
|
|
|
2022-10-17 14:01:44 +05:30
|
|
|
const cors = (req: Request, res: Response, next: NextFunction) => {
|
|
|
|
res.header('Access-Control-Allow-Origin', '*');
|
|
|
|
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
|
|
|
|
res.header('Access-Control-Allow-Headers', 'Content-Type');
|
|
|
|
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
|
2022-09-22 15:35:22 +05:30
|
|
|
async function createServer() {
|
|
|
|
const app = express();
|
|
|
|
|
|
|
|
// Create Vite server in middleware mode
|
|
|
|
const vite = await createViteServer({
|
|
|
|
configFile: './vite.config.ts',
|
|
|
|
server: { middlewareMode: true },
|
|
|
|
appType: 'custom', // don't include Vite's default HTML handling middlewares
|
|
|
|
});
|
|
|
|
|
2022-10-17 14:01:44 +05:30
|
|
|
app.use(cors);
|
2022-09-28 19:52:31 +01:00
|
|
|
app.use(express.static('./packages/mermaid/dist'));
|
2022-10-03 07:01:56 +02:00
|
|
|
app.use(express.static('./packages/mermaid-example-diagram/dist'));
|
|
|
|
app.use(express.static('./packages/mermaid-mindmap/dist'));
|
2022-10-03 10:05:12 +02:00
|
|
|
app.use(vite.middlewares);
|
2022-09-22 15:35:22 +05:30
|
|
|
app.use(express.static('demos'));
|
|
|
|
app.use(express.static('cypress/platform'));
|
|
|
|
|
|
|
|
app.listen(9000, () => {
|
|
|
|
console.log(`Listening on http://localhost:9000`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// build(getBuildConfig({ minify: false, watch: true }));
|
|
|
|
createServer();
|