commit 5146808c2f29a26c905dac7d5f89da8ede31ec7f
Author: ZZY <2450266535@qq.com>
Date: Tue Oct 22 15:08:26 2024 +0800
init
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2b7f48b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+.*
+!.gitignore
+node_modules/
+package-lock.json
\ No newline at end of file
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..14c0de5
--- /dev/null
+++ b/index.js
@@ -0,0 +1,41 @@
+const express = require('express');
+const app = express();
+const port = 8081;
+
+app.use(express.json());
+app.use(express.urlencoded({ extended: false }));
+app.use(express.static('static'));
+
+app.post('/login', (req, res) => {
+ const { username, password } = req.body;
+
+ // 模拟登录验证
+ if (username === '123' && password === '123') {
+ // res.redirect(302, '/success.html');
+ res.json({ success: true, redirectUrl: '/success.html' });
+ } else {
+ res.status(401).json({ success: false, message: 'Invalid credentials' });
+ }
+});
+
+// catch 404 and forward to error handler
+app.use(function(req, res, next) {
+ res.status(404);
+ res.end('
404 Not Found
');
+});
+
+// error handler
+app.use(function(err, req, res, next) {
+ // set locals, only providing error in development
+ res.locals.message = err.message;
+ res.locals.error = req.app.get('env') === 'development' ? err : {};
+
+ console.log(err);
+ // render the error page
+ res.status(err.status || 500);
+ res.end('error
');
+});
+
+app.listen(port, () => {
+ console.log(`Server running at http://127.0.0.1:${port}`);
+});
\ No newline at end of file
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..2e5412e
--- /dev/null
+++ b/package.json
@@ -0,0 +1,16 @@
+{
+ "name": "html",
+ "version": "1.0.0",
+ "main": "index.js",
+ "scripts": {
+ "start": "nodemon index.js",
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "author": "",
+ "license": "ISC",
+ "description": "",
+ "dependencies": {
+ "express": "^4.21.1",
+ "nodemon": "^3.1.7"
+ }
+}
diff --git a/static/index.html b/static/index.html
new file mode 100644
index 0000000..44d6476
--- /dev/null
+++ b/static/index.html
@@ -0,0 +1,57 @@
+
+
+
+
+
+ Login Form
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/static/success.html b/static/success.html
new file mode 100644
index 0000000..b8d5f1d
--- /dev/null
+++ b/static/success.html
@@ -0,0 +1,11 @@
+
+
+
+
+
+ Document
+
+
+ Successful
+
+
\ No newline at end of file