-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
37 lines (29 loc) · 930 Bytes
/
server.js
File metadata and controls
37 lines (29 loc) · 930 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
27
28
29
30
31
32
33
34
35
36
37
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = 3000;
// Middleware
app.use(bodyParser.json());
// Array to store submitted data (replace this with a database in a real application)
let submittedData = [];
// Endpoint to receive form submissions
app.post('/api/submit-form', (req, res) => {
const formData = req.body;
submittedData.push(formData);
res.status(201).send('Form data submitted successfully');
});
// Endpoint to retrieve all submitted data
app.get('/api/submitted-data', (req, res) => {
res.json(submittedData);
});
// 处理根路径的请求
app.get('/', (req, res) => {
res.send('Welcome to my Express server!');
});
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
// 处理根路径的请求
app.get('/', (req, res) => {
res.send('Welcome to my Express server!');
});