-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
68 lines (54 loc) · 1.51 KB
/
index.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
安装依赖: npm install encryptLong crypto-js express
*/
/* -------------------------模拟浏览器环境------------------------- */
const { JSDOM } = require("jsdom");
const DOM = new JSDOM(`
<!DOCTYPE html>
<body>
</body>
`);
global.window = DOM.window
global.navigator = window.navigator
global.document = window.document
/* -------------------------前端常用加解密------------------------- */
/*
JSEncrypt 基于RSA的加密库
作者: yinsel
关键词: JSEncrypt、setPublicKey、encryptLong、decryptLong
*/
const JSEncrypt = require("encryptlong").default;
const jsencrypt = new JSEncrypt()
console.log(jsencrypt)
/*
CryptoJS 多功能加密库
作者: yinsel
关键词: JSEncrypt、setPublicKey、encryptLong、decryptLong
*/
const CryptoJS = require("crypto-js")
console.log(CryptoJS)
/*
Express 简易HTTP服务器
*/
const express = require('express');
const app = express();
const port = 3000; // 服务器监听端口
// 中间件,用于解析JSON格式的请求体
app.use(express.json());
// 创建一个简单的GET路由
app.get('/get', (req, res) => {
res.send('Hello, Express!');
});
// 创建一个POST路由,处理JSON数据
app.post('/post', (req, res) => {
// 返回响应,包含接收到的JSON数据
const jsonData = req.body
console.log(jsonData)
res.json({
data: "Hello Express!"
});
});
// 启动服务器
app.listen(port, () => {
console.log(`Server is running at http://localhost:${port}`);
});