-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
26 lines (20 loc) · 740 Bytes
/
Copy pathserver.js
File metadata and controls
26 lines (20 loc) · 740 Bytes
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
const express = require("express");
const cookieParser = require("cookie-parser");
const csrfMiddleware = require("./middlewares/csrfProtection");
const path = require("path");
const app = express();
const PORT = 5001;
app.use(cookieParser());
app.use(express.json());
app.use(express.static(path.join(__dirname, "assets")));
app.get("/", csrfMiddleware, (req, res) => {
res.sendFile(path.join(__dirname, "assets", "form.html"));
});
app.post("/api/submit-form", csrfMiddleware, (req, res) => {
const {username} = req.body;
console.log("Received username: ",username);
res.json({ message: "Form submitted successfully!" });
})
app.listen(PORT, ()=>{
console.log(`Server is running on http://localhost:${PORT}`)
});