我正在使用Pieter Soudan的Meteor Meetup Antwerp所示的结构设计
我通过使用不同的命名空间名称(UserAuth,AppRoute)取得了成功,具体取决于我的模块的功能。但是我希望有一个特定于应用程序的命名空间UP(UserPortal),并且拥有像UP.UserAuth,UP.AppRoutes这样的命名空间。
我似乎无法在UP.UserAuth中调用检查登录的函数。
我的应用程序包package.js看起来像这样
Package.describe({
name: 'up-app',
version: '0.0.1',
summary: 'User Portal Application',
});
var both=['server','client'];
var server ='server';
var client ='client';
Package.onUse(function(api) {
api.versionsFrom('1.0.3.2');
api.use('templating',client);
api.use('iron:router@1.0.7',both);
api.use('tracker',both);
api.use('underscore',both);
api.use('blaze',both);
api.use(['up-user-auth'],both);
api.addFiles(['lib/namespace.js','lib/routes.js'],both);
api.addFiles(['views/dashboard.html','views/loading.html'],client);
api.export('UP');
});
Package.onTest(function(api) {
api.use('tinytest');
api.use('up-app');
api.addFiles('tests/up-app-tests.js');
});
我打算使用up-app在单个包中声明我的所有app依赖项。
我的up-app / lib / routes.js文件如下所示:
Router.configure({
layoutTemplate: 'upDashBoard',
loadingTemplate: 'upLoading'
});
Router.onBeforeAction(UP.UserAuth.loginRequired, {
except: ['login','install']
});
Router.route('/', {
name: 'home'
});
我的up-user-auth软件包在package.js
中有这个Package.describe({
name: 'up-user-auth',
version: '0.0.1',
// Brief, one-line summary of the package.
summary: 'User Authentication and Roles Management',
});
Package.onUse(function(api) {
var both = ['server', 'client'];
var server = 'server';
var client = 'client';
api.versionsFrom('1.0.3.2');
api.use([
'tracker',
'service-configuration',
'accounts-base',
'underscore',
'templating',
'blaze',
'session',
'sha',
]
,client);
api.use([
'tracker',
'service-configuration',
'accounts-password',
'accounts-base',
'underscore',]
,server);
api.use(['iron:router@1.0.1','copleykj:mesosphere'], both);
api.imply(['accounts-base','accounts-password'], both);
api.addFiles(['lib/namespace.js','lib/loginValidation.js','lib/loginMethods.js'],both);
api.export('UP', both);
});
Package.onTest(function(api) {
api.use('tinytest');
api.use('up-user-auth');
api.addFiles('tests/server/up-user-auth-tests.js');
});
我的up / lib / namespace.js看起来像这样:
UP={};
UP.UserAuth={
loginRequired: function() {
return console.log("loginControllers");
}
}
如果我删除对UP={};
的第二个引用,那么我会收到错误消息
无法设置未定义的属性'UserAuth'但是当我添加它时,我得到的是无法读取未定义的属性'loginRequired'
我做错了什么?
答案 0 :(得分:0)
您忘记声明主程序包'up-app'的依赖关系。 每个使用命名空间UP的包都应该声明对导出命名空间的包的依赖。
所以,只需添加
api.use('up-app', ['client', 'server']);
在up-user-auth / package.js
中氪, 彼得