我想从请求中获取客户端请求的URL.
目前我使用:
var requestedUrl = req.protocol + '://' + req.host + ':3000' + req.url;
Run Code Online (Sandbox Code Playgroud)
这根本不是很好.它还遗漏了我需要的url片段(#/ something).
有没有办法可以获得完整的网址?也许在标题之外?
问候
我有些问题了解如何使用"q"(https://github.com/kriskowal/q)javascript的promises库:
var delayOne = function() {
setTimeout(function() {
return 'hi';
}, 100);
};
var delayTwo = function(preValue) {
setTimeout(function() {
return preValue + ' my name';
}, 200);
};
var delayThree = function(preValue) {
setTimeout(function() {
return preValue + ' is bodo';
}, 300);
};
var delayFour = function(preValue) {
setTimeout(function() {
console.log(preValue);
}, 400);
};
Q.fcall(delayOne).then(delayTwo).then(delayThree).then(delayFour).end();
Run Code Online (Sandbox Code Playgroud)
这只返回undefined ...
我想将64位整数分成两个32位整数:
var bigInt = 0xffffff;
var highInt = bigInt >> 8 // get the high bits 0xfff
var lowInt = bigInt // cut of the first part (with &)?
console.log(highInt); // 0xfff
console.log(lowInt); // 0xfff
// set them together again
var reBigInt = (highInt << 8) + lowInt;
Run Code Online (Sandbox Code Playgroud)
不幸的是,既没有获得highInt也没有获得lowInt的工作......有人能给我答案我需要如何使用按位运算符吗?
问候
我正在编写一个测试,我希望将结果json.Marshal与静态json字符串进行比较:
var json = []byte(`{
"foo": "bar"
}`)
Run Code Online (Sandbox Code Playgroud)
作为结果json.Marshal没有任何\n,\t和空格我以为我可以很容易做到:
bytes.Trim(json, " \n\t")
Run Code Online (Sandbox Code Playgroud)
删除所有这些字符.但不幸的是,这不起作用.我可以编写自定义修剪功能并使用,bytes.TrimFunc但这对我来说似乎很复杂.
还有什么办法让json字符串"压缩"尽可能少的代码?
最好,博
我想检查一下Backbone.View当前是否在DOM中呈现,如果不是我不必重新呈现它.我能以某种方式检查吗?
问候
我目前遇到的问题是我有一个应该侦听另一个对象的对象.
问题是:我该如何处理订阅?目前,我只知道两种可能的方法:
使用registrator:
var Registrator = function() {
this.listener = new Listener();
};
Registrator.prototype.register = function(subsriber) {
var self = this;
subscriber.on('event', function(info) {
self.listener.doSomething(info);
});
};
Run Code Online (Sandbox Code Playgroud)
在构造函数中:
var Subscriber = function() {
var listener = require('./instanced-listener');
this.on('event', function(info) {
listener.doSomething(info);
});
};
Run Code Online (Sandbox Code Playgroud)
如您所见,这两种方法都不是那么整洁.还有其他模式我可以用于这个问题吗?
问候
PS:
如果示例看起来太抽象,那么这里是源代码:
https://github.com/bodokaiser/documents/blob/master/lib/repository.js
检查构造函数以查看我的不快乐:)
我想设置从一台服务器为多个站点提供服务:
1. http://www.example.org => node.js-www (running on port (50000)
2. http://files.example.org => node.js-files (running on port 50001)
Run Code Online (Sandbox Code Playgroud)
直到现在我才发现docker在使用静态ip时进行端口重定向。
实际上可以使用 docker 通过主机名进行端口重定向吗?
我使用免费的亚马逊 EC2 实例。
谢谢博
编辑:我想让多个节点应用程序在同一端口上运行,但提供不同的主机名。
我正在使用symfony.com的cookbook文章来实现图像的文件上传选项.
现在我想将其他图像加载到实体.
编辑的默认策略是:1.取出DB 2.注入表3.坚持
不知何故,当使用文件上传时,该策略不再起作用(doctrine不执行事件)
我还能做些什么来使图片的文章可编辑?
我有一个Backbone View,它向服务器发送Ajax调用以删除会话.
在服务器上跟随事件被触发:
app.delete('/session', function(req, res) {
if (req.session) {
req.session.destroy(function() {
res.clearCookie('connect.sid', { path: '/' });
res.send('removed session', 200);
});
} else {
res.send('no session assigned', 500);
}
});
Run Code Online (Sandbox Code Playgroud)
奇怪的是,我可以多次按下注销按钮而不会收到HTTP 500错误代码.铬也告诉我饼干仍然存在.
出了什么问题?
问候
编辑:
我发现这不是一个会话问题,而是一个cookie问题.我在路线上添加了res.clearCookie.不幸的是,行为(cookie,会话保持活跃)没有改变
EDIT2:我现在给res.clearCookie一些参数=> res.clearCookie('connect.sid',{path:'/'}); 现在至少cookie已经在浏览器中消失了.但会议似乎仍然可用.或者至少我可以调用注销路径我甚至需要req.session应该是假的
编辑3: 我现在从redis中删除了所有会话并重新启动了所有内容(redis,node,browser).比我再次登录并退出.这工作到目前为止,但当我用F5重新登录页面时,我得到一个新的会话.为什么?
我目前使用 git 的方式如下:
不幸的是,这有时会变得混乱。我想做的是将一些较小的提交合并到一个较大的提交中。
此外,有时将新分支中的所有提交合并到一个提交并将其合并到 master 也是一个好主意。
例子:
git branch update-docs
git checkout update-docs
git add -A .
git commit -m 'updated networking doc'
git add -A .
git commit -m 'updated manager doc'
git checkout master
git merge update-docs
Run Code Online (Sandbox Code Playgroud)
正如您现在所知,我将在主分支“更新的网络文档”和“更新的管理器文档”中进行两次提交。
如果我现在只想在 master 分支中有一个名为“更新的文档”的提交,例如,其中包含这两个提交的更改,我该怎么办?
我认为你必须使用 git rebase 来完成此类任务。我只是不知道如何使用它。
我已经尝试过:
git checkout master
git rebase update-docs
Run Code Online (Sandbox Code Playgroud)
但这将更改合并到 master 而不留下任何提交,现在存储库被搞乱了。
那么有人会分享您必须使用的命令吗?
解决方案:
git checkout -b update-readme
git commit -am 'rewritten readme'
git commit -am 'added author …Run Code Online (Sandbox Code Playgroud) javascript ×5
node.js ×3
express ×2
asynchronous ×1
backbone.js ×1
byte ×1
callback ×1
commonjs ×1
dns ×1
docker ×1
doctrine-orm ×1
dom ×1
entity ×1
file-upload ×1
git ×1
git-merge ×1
git-rebase ×1
go ×1
hostname ×1
integer ×1
json ×1
module ×1
port ×1
promise ×1
q ×1
rebase ×1
redirect ×1
session ×1
symfony ×1
view ×1