From 5146808c2f29a26c905dac7d5f89da8ede31ec7f Mon Sep 17 00:00:00 2001 From: ZZY <2450266535@qq.com> Date: Tue, 22 Oct 2024 15:08:26 +0800 Subject: [PATCH] init --- .gitignore | 4 ++++ index.js | 41 ++++++++++++++++++++++++++++++++ package.json | 16 +++++++++++++ static/index.html | 57 +++++++++++++++++++++++++++++++++++++++++++++ static/success.html | 11 +++++++++ 5 files changed, 129 insertions(+) create mode 100644 .gitignore create mode 100644 index.js create mode 100644 package.json create mode 100644 static/index.html create mode 100644 static/success.html 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('