我创建了许多不同的项目,基本上它们都存储在文件夹中,并且一些笔记写在这些文件夹中的笔记本中。
但是,当您需要从以前的项目中提取一些有用的功能,或者再次记住如何绕过错误或记住命令等时。在文件夹和笔记本中查找信息需要很长时间。
而且您还需要定期进行备份...
我尝试了很多方法,但不知何故就是无法生根发芽。
请告知您如何存储有用的想法、命令、代码、解决方案等。 ?
我创建了许多不同的项目,基本上它们都存储在文件夹中,并且一些笔记写在这些文件夹中的笔记本中。
但是,当您需要从以前的项目中提取一些有用的功能,或者再次记住如何绕过错误或记住命令等时。在文件夹和笔记本中查找信息需要很长时间。
而且您还需要定期进行备份...
我尝试了很多方法,但不知何故就是无法生根发芽。
请告知您如何存储有用的想法、命令、代码、解决方案等。 ?
在 expressjs 中,使用中间件层通过类来处理传入的调用
/middlewares/index.js
class Middlewares {
constructor(options) {
this.options = options;
}
general(req, res, next) {
console.log(this.options)
}
test() {
console.log(this.options)
}
}
export default Middlewares;
在app.js
import express from 'express';
import { createServer } from 'http';
import Middlewares from './middlewares/index.js'
const app = express();
const options = {
whiteListSite: ['http://localhost:81', 'http://localhost:83'],
};
const server = createServer(app);
const middlewares = new Middlewares(options);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(middlewares.general); //<-- получаю ошибку TypeError: Cannot read properties of undefined (reading 'options')
middlewares.test() //<-- здесь срабатывает все, в консоль выводиться { whiteListSite: [ 'http://localhost:81', 'http://localhost:83' ] }
app.get('/', function(req, res) {
res.send('hello world');
});
server.listen(8080, () => {
console.log(`GateWay app listening on port ${8080}`);
});
在服务器操作期间,当触发处理程序时,即对路由发出任何请求时,函数中general都会生成错误TypeError: Cannot read properties of undefined (reading 'options'),但是当我调用 test() 时,一切都正常运行,没有失败
也就是说,类的函数不能从类构造函数中获取变量。这和什么有关?
我正在研究如何最好地在数据库中存储密码这个课题。我发现所有现代网站都将密码哈希存储在数据库中,然后通过相同的哈希函数传递用户输入的文本并比较哈希值。但在所有授权示例中,仅对密码进行了散列。电子邮件或登录信息以明文形式存储。如果您对登录名和电子邮件进行哈希处理,并在检查时将它们传递给哈希函数,就像密码一样,会发生什么?然后攻击者将只能访问哈希,但不能访问可以在其他网站上使用的电话号码或电子邮件。他们为什么不这么做呢?数据库是否会占用更多空间?或者是因为哈希函数很慢所以它们不这样做?这种方法有什么缺点?
书中的例子
func main() {
var count1 *int
count2:= new(int)
countTemp:= 5
count3:= &countTemp
t:= &time.Time{}
fmt.Printf("count1: %#v\n", count1)
fmt.Printf("count2: %#v\n", count2)
fmt.Printf("count3: %#v\n", count3)
fmt.Printf("time: %#v\n", t)
}
在输出中我们得到
count1: (*int)(nil)
count2: (*int)(0xc00000a0c8)
count3: (*int)(0xc00000a0e0)
time: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)
指向 countTemp 的指针和指向时间的指针有什么区别,为什么我们从时间中获取值
在服务器上 nginx 1.10.3
已创建测试存根,以 200 和静态 json 响应任何请求
cat mockserver.test.conf
server {
listen 80;
server_name mockserver.test;
location / {
return 200 '{"name": "qwerty", "phone": "+123"}';
}
}
如何配置 nginx,以便通过 POST 请求发送数据
POST http://mockserver.test/
{"token": "+444"}
响应是 json
{"name": "qwerty", "phone": "+444"}
也就是说,POST 请求中的键的值phone被替换为响应键的值。token
https://nginx.org/en/docs/varindex.html
尝试使用:
return 200 '{"phone": "$request_body"}'- 返回一个空字符串
return 200 '{"phone": "$request"}'- 仅返回POST / HTTP/1.1
已更新以反映评论。