Add dev server
This commit is contained in:
		
					parent
					
						
							
								03379ac1a7
							
						
					
				
			
			
				commit
				
					
						8841784cae
					
				
			
		
					 4 changed files with 1043 additions and 1 deletions
				
			
		
							
								
								
									
										993
									
								
								package-lock.json
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										993
									
								
								package-lock.json
									
										
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							| 
						 | 
					@ -2,6 +2,7 @@
 | 
				
			||||||
  "version": "0.0.0",
 | 
					  "version": "0.0.0",
 | 
				
			||||||
  "scripts": {
 | 
					  "scripts": {
 | 
				
			||||||
    "dev": "vite",
 | 
					    "dev": "vite",
 | 
				
			||||||
 | 
					    "dev-server": "node ./server.js",
 | 
				
			||||||
    "build": "vite build",
 | 
					    "build": "vite build",
 | 
				
			||||||
    "serve": "vite preview"
 | 
					    "serve": "vite preview"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
| 
						 | 
					@ -15,6 +16,8 @@
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "devDependencies": {
 | 
					  "devDependencies": {
 | 
				
			||||||
    "@vitejs/plugin-react-refresh": "^1.3.1",
 | 
					    "@vitejs/plugin-react-refresh": "^1.3.1",
 | 
				
			||||||
 | 
					    "express": "^4.17.1",
 | 
				
			||||||
 | 
					    "http2-proxy": "^5.0.53",
 | 
				
			||||||
    "vite": "^2.4.2"
 | 
					    "vite": "^2.4.2"
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										46
									
								
								server.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								server.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,46 @@
 | 
				
			||||||
 | 
					const express = require("express");
 | 
				
			||||||
 | 
					const { createServer: createViteServer } = require("vite");
 | 
				
			||||||
 | 
					const proxy = require("http2-proxy");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					async function createServer() {
 | 
				
			||||||
 | 
					  const app = express();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  app.use("/_matrix*", (req, res, next) => {
 | 
				
			||||||
 | 
					    proxy.web(
 | 
				
			||||||
 | 
					      req,
 | 
				
			||||||
 | 
					      res,
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        hostname: "localhost",
 | 
				
			||||||
 | 
					        port: 8008,
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      (err) => {
 | 
				
			||||||
 | 
					        if (err) {
 | 
				
			||||||
 | 
					          console.error(
 | 
				
			||||||
 | 
					            `Error http://localhost:3000${req.originalUrl} -> http://localhost:8008${req.originalUrl}`,
 | 
				
			||||||
 | 
					            err
 | 
				
			||||||
 | 
					          );
 | 
				
			||||||
 | 
					          next(err);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					          console.log(
 | 
				
			||||||
 | 
					            `http://localhost:3000${req.originalUrl} -> http://localhost:8008${req.originalUrl}`
 | 
				
			||||||
 | 
					          );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Create vite server in middleware mode.
 | 
				
			||||||
 | 
					  const vite = await createViteServer({
 | 
				
			||||||
 | 
					    server: { middlewareMode: "html" },
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  // Use vite's connect instance as middleware
 | 
				
			||||||
 | 
					  app.use(vite.middlewares);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  app.listen(3000);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					createServer()
 | 
				
			||||||
 | 
					  .then(() => {
 | 
				
			||||||
 | 
					    console.log("Listening on http://localhost:3000");
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					  .catch((err) => console.error(err));
 | 
				
			||||||
| 
						 | 
					@ -22,7 +22,7 @@ export default defineConfig({
 | 
				
			||||||
  plugins: [reactRefresh()],
 | 
					  plugins: [reactRefresh()],
 | 
				
			||||||
  server: {
 | 
					  server: {
 | 
				
			||||||
    proxy: {
 | 
					    proxy: {
 | 
				
			||||||
      "/_matrix": "http://localhost:8080",
 | 
					      "/_matrix": "http://localhost:8008",
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue