来自express.js,我想为一个小项目尝试熨斗.然而,有一些小问题使我无法真正到达某个地方.
var flatiron = require('flatiron')
, session = require('connect').session
, ecstatic = require('ecstatic')
, path = require('path')
, fs = require('fs')
, plates = require('plates')
, director = require('director')
, winston = require('winston')
, union = require('union');
var router = new director.http.Router();
var server = union.createServer({
before: [
ecstatic(__dirname + '/public')
]
});
router.get('/', function () {
var self = this;
fs.readFile('public/layout.html', 'utf-8', function(err, html) {
[...]
})
});
server.listen(3000, function () {
console.log('Application is now started on …Run Code Online (Sandbox Code Playgroud) 我刚刚开始看盘子,因为很多人都在谈论它.
有一些带有少量html片段的板块的例子,但实际上并不是一个完整的模板文件.所以我想知道如何将布局分成layout.html文件并将内容分成几个content.html文件?
另外,我想知道flatiron.js/plate中是否有一些针对多语言网站的策略?
谢谢!
- if (typeof(person) == 'undefined')
input(type="text", name="person[Name]")
- else
input(type="text", name="person[Name]", value="#{person.Name}")
Run Code Online (Sandbox Code Playgroud)
有没有办法写这个内联?我有一个选项选择,我不想为30+值做一个条件语句来选择正确的选项.
有没有办法在初始化后更改nano中的配置参数?我想初始纳米:
nano = require('nano')('http://127.0.0.1:5984')
Run Code Online (Sandbox Code Playgroud)
用户提交登录表单后,更改用户和密码.我总是收到一个错误:
nano.cfg.user = params.user.name
TypeError: Cannot set property 'user' of undefined
Run Code Online (Sandbox Code Playgroud)
或者我应该fork nano并编写auth函数来调整值?
Passport.js为node.js和Express提供了很好的身份验证,包括一个中间件解决方案:
ensureAuthenticated = function(req, res, next) {
if (req.isAuthenticated()) {
return next();
}
return res.redirect("/login");
};
Run Code Online (Sandbox Code Playgroud)
如何在快速资源模块中使用此中间件?不幸,
app.resource('users', ensureAuthenticated, require('./resources/users'));
Run Code Online (Sandbox Code Playgroud)
不起作用.
我正在使用客户端上需要的几个 node.js 模块:
索引.js:
var sync = require('../lib/sync');
Run Code Online (Sandbox Code Playgroud)
所以我认为 browserify 可能是最好的选择。捆绑文件效果很好,但是 browserify 将所有内容都包装在(function(){my code here})();导致Can't find variable: require错误的 a 中。我怎样才能防止这种行为?
当我取下包装时,一切都按预期进行,没有错误。
我正在使用angular-http-auth模块拦截401响应.event:auth-loginRequired如果有一个可以用$ on()接收的401响应,则该模块进行广播.但是我怎么测试呢?
beforeEach(inject(function($injector, $rootScope) {
$httpBackend = $injector.get('$httpBackend');
myApi = $injector.get('myApi');
scope = $rootScope.$new();
spyOn($scope, '$on').andCallThrough();
}));
describe('API Client Test', function() {
it('should return 401', function() {
$httpBackend.when('GET', myApi.config.apiRoot + '/user').respond(401, '');
myApi.get(function(error, success) {
// this never gets triggered as 401 are intercepted
});
scope.$on('event:auth-loginRequired', function() {
// This works!
console.log('fired');
});
// This doesn't work
expect($scope.$on).toHaveBeenCalledWith('event:auth-loginRequired', jasmine.any(Function));
$httpBackend.flush();
});
});
Run Code Online (Sandbox Code Playgroud) 我想优雅地从主进程退出子进程,其中主代码和子代码在不同的.js文件中.
master.js
cluster.setupMaster({
exec : 'child.js',
args : [],
silent : false
});
cluster.fork({'some': 'info'});
process.on('SIGINT', function() {
console.log('\nshutting down services ...');
function eachWorker(callback) {
for (var id in cluster.workers) {
callback(cluster.workers[id]);
}
}
eachWorker(function(worker) {
worker.kill();
});
process.exit(0);
})
Run Code Online (Sandbox Code Playgroud)
child.js
cluster.worker.on('disconnect', function() {
console.log(cluster.worker.id + ' shutting down.');
})
Run Code Online (Sandbox Code Playgroud)
我尝试了各种信号,cluster.worker.on('exit'),process.on('exit'),process.on('disconnect')等,但似乎没有触发.有任何想法吗?
worker.send()在执行期间工作,但不在SIGINT函数内?
这是我从CouchDB数据库中检索的原始JSON对象:
{
"total_rows": 3,
"offset": 0,
"rows": [
{
"id": "1e8fe199d4e761b71bb8920eb3003db2",
"key": null,
"value": {
"_id": "1e8fe199d4e761b71bb8920eb3003db2",
"_rev": "3-6979e0cd646f2bc0ddf84c0664d25808",
"Room_number": 99,
"Location": "City campus",
"Timetable": {
"Monday": [
"08:30",
"10:00",
"11:30",
"13:30",
"14:14"
],
"Tuesday": [
"08:30",
"10:00",
"11:30",
"13:30",
"14:14"
],
"Sunday": [
"08:30",
"10:00",
"11:30",
"13:30",
"14:14"
]
}
}
},
{
"id": "1e8fe199d4e761b71bb8920eb3004cc6",
"key": null,
"value": {
"_id": "1e8fe199d4e761b71bb8920eb3004cc6",
"_rev": "2-f7250cca62a804137174a20f48312c40",
"Room_number": 12,
"Location": "City hall",
"Timetable": {
"Monday": [
"08:30",
"10:00",
"11:30", …Run Code Online (Sandbox Code Playgroud) node.js ×8
javascript ×7
express ×2
flatiron.js ×2
angularjs ×1
browserify ×1
connect ×1
couchdb ×1
couchdb-nano ×1
direnv ×1
docker ×1
jasmine ×1
karma-runner ×1
middleware ×1
pug ×1
templates ×1
testing ×1
url-routing ×1