-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
36 lines (28 loc) · 907 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import express from "express";
import { createServer as createViteServer } from "vite";
import multer from "multer";
const upload = multer(); // to handle multipart/form-data
async function startServer() {
const app = express();
// Routes
app.get("/submit", upload.none(), (req, res) => {
console.log("req.query", req.query);
res.type("html");
res.send("<form>WORKED WITH GET</form>");
});
app.post("/submit", upload.none(), (req, res) => {
console.log("req.body", req.body);
res.type("html");
res.send("<form>WORKED WITH POST</form>");
});
// Create Vite dev server in middleware mode
const vite = await createViteServer({
server: { middlewareMode: true },
});
// Use Vite's middleware to serve front-end files
app.use(vite.middlewares);
app.listen(3000, () => {
console.log("Server running at http://localhost:3000");
});
}
startServer();