无法在请求中获取已设置的Cookie.
我用我的饼干
response.cookie('name', 'My name');
Run Code Online (Sandbox Code Playgroud)
我想以这种方式获取我的cookie,它之前有效,但我改变了快速配置,我现在不知道什么是问题.
request.cookies is and empty Object
Run Code Online (Sandbox Code Playgroud)
我的快递配置:
var express = require('express'),
api = require('./routes/api');
var app = express();
app.configure(function () {
app.set('port', process.env.PORT || 3000);
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
//app.use(express.bodyParser());
app.use(express.compress()); // New call to compress content
app.use(express.cookieParser());
app.use(express.session({secret: 'secret'}));
app.use(app.router);
app.use(express.methodOverride());
//app.use(express.static(__dirname + '/public'));
});
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header("Access-Control-Allow-Headers", "X-Requested-With, Content-Type");
next();
});
app.configure('development', function () {
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function () {
app.use(express.errorHandler()); …Run Code Online (Sandbox Code Playgroud) 我想用 nodejs 打开谷歌浏览器,但出现此错误(我使用了 execFile 和 spawn),
代码
var execFile = require('child_process').execFile,
spawn = require('child_process').spawn,
spawn('C\\Program Files\\Google\\Chrome\\Application\\chrome.exe', function (error, stdout, stderr) {
if (error !== null) { console.log('exec error: ' + error); }
});
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:998:11)
at Process.ChildProcess._handle.onexit (child_process.js:789:34)
Run Code Online (Sandbox Code Playgroud) 当我使用put或delete时,它变成OPTIONS.我正在为我的服务器框架使用expressjs.
客户:
$http({
method: 'DELETE',
url: HTTP_URL + '/update/account',
params: { mail: mail }
});
Run Code Online (Sandbox Code Playgroud)
服务器:
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Credentials", true);
res.header('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE');
res.header("Access-Control-Allow-Headers",
'Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept');
next();
});
Run Code Online (Sandbox Code Playgroud) 模板和templateUrl之间有多少性能差异?
目前我在我的所有指令中使用模板,但因为我对性能很着迷,我现在想,这更快.
如果我使用templateUrl + $ templateCache,那么这只是在指令中使用模板更快吗?
我已将整个文件夹映射到工作区中的属性中,但它不起作用.当我映射单个文件,然后在那里进行的更改工作.为什么?
我的问题是如何在可放置区域上拖放项目时创建动态网格.
我想使用jquery UI,因为我只需要它来实现这个功能,而且这只是一个很多代码.
我想做这样的事情http://mcpants.github.io/jquery.shapeshift/但不那么复杂.
我将附上我网格的屏幕截图.可拖动的元素是"ddd".
它是一个angularjs APP,我使用这个库进行拖放:https://github.com/fatlinesofcode/ngDraggable
试图使用这个库,但我可以让它工作:https: //github.com/RubaXa/Sortable
有什么建议?
我有一个弹出指令,我想编译并将其附加到正文.是否有一种更简单的方法,然后重新编译并将指令附加到body.
link: function (scope, element) {
$('body').append($compile('html')(scope.new()))
}
Run Code Online (Sandbox Code Playgroud)
我不想两次编译指令,第一次自动编译,第二次手动编译.如果有属性或设置,它会自动将指令附加到body,这将是很好的.
当我尝试使用angular.js的$ http模块来授权twitter应用程序时,我总是得到:
XMLHttpRequest cannot load https://api.twitter.com/oauth/authenticate?oauth_token=something. Origin null is not allowed by Access-Control-Allow-Origin.
Run Code Online (Sandbox Code Playgroud)
客户代码:
$http({
method: 'GET',
headers: { "Content-Type": undefined },
url: '/oauth/twitter'
});
Run Code Online (Sandbox Code Playgroud)
服务器代码:
app.configure(function () {
app.use(express.cookieParser());
app.use(express.cookieSession({ secret: 'tobo!', cookie: { maxAge: 3600 }}));
app.use(express.session({secret: 'secret'}));
app.use(passport.initialize());
app.use(passport.session());
});
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Credentials", true);
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header("Access-Control-Allow-Headers",
'Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept');
next();
});
app.get('/oauth/twitter', passport.authenticate('twitter'), function (req, res) {
// The request will be redirected to Twitter for authentication, so this …Run Code Online (Sandbox Code Playgroud) http://www.html5rocks.com/en/tutorials/dnd/basics/
在这里的示例中(滚动到底部并尝试最后一个示例),当您拖出元素并且不将其放在任何位置时,它会回到默认位置并且有一个动画可以定位到其默认位置(镀铬/ Safari浏览器).我想禁用该动画.
webkit是否有某种特殊属性,允许我这样做?
我正在尝试在 iframe 内初始化服务工作者。我知道服务人员在起源时有安全限制,但据我了解,设置base应该可以解决这个问题。
<html>
<base href="http://127.0.0.1:9090">
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/sw.js').then(function(reg) {
if(reg.installing) {
console.log('Service worker installing');
} else if(reg.waiting) {
console.log('Service worker installed');
} else if(reg.active) {
console.log('Service worker active');
console.log(self)
}
}).catch(function(error) {
// registration failed
console.log('Registration failed with ' + error);
});
});
}
</script>
Run Code Online (Sandbox Code Playgroud)
错误:
Registration failed with InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state.
如果我修改基础,它会抱怨起源不同,因此服务工作人员在某种程度上与基础 href 有关。我在这里缺少什么?
感谢您的帮助
我希望MongoDB在%秒通过后清除其集合中的数据.我正在设置索引,但一段时间后收集不会被清除,所有文件仍然存在.
我究竟做错了什么?
数据库版本:3.2
设定指数:
db.collection('history').ensureIndex(
{ '_id': 1, 'created': 1 },
{ unique: true, background: true, w: 1, expireAfterSeconds: 60}
);
// or
db.collection('history').createIndex(
{ '_id': 1, 'created': 1 },
{ unique: true, background: true, w: 1, expireAfterSeconds: 60}
);
// history document
var _history = {
_id: new ObjectId(),
created: new Date()
};
Run Code Online (Sandbox Code Playgroud)
收集历史,索引:
var historyCollectionIndex = [
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "guardian_dev.history"
},
{
"v" : …Run Code Online (Sandbox Code Playgroud) 为什么对象属性未定义,在记录整个对象时,情况并非如此.
这个日志:
console.log(JSON.stringify(obj));
[{"id":"base_data","title":"Base Data","widgetId":"base_data"}]
console.log(obj.title);
undefined
Run Code Online (Sandbox Code Playgroud)
为什么???