search and replace ```\n< with ```\n\n< to ensure there's an empty line before closing tags
2.8 KiB
2.8 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
589690e6f9fc0f352b528e6e | Clean Up Your Project with Modules | 2 | 使用模块清理项目 |
Description
module.exports = function(app,db){现在位于服务器文件的顶部,需要这样的文件:}
const routes = require('./routes.js');
在您与数据库建立成功连接之后,实例化它们中的每一个如下: routes(app, db)
最后,获取服务器中的所有路由并将它们粘贴到新文件中并从服务器文件中删除它们。也可以使用ensureAuthenticated,因为我们专门为路由创建了中间件功能。您现在必须正确添加所使用的依赖项,例如const passport = require('passport');
,在routes.js文件中导出行的最上方。继续添加它们直到不再存在错误,并且您的服务器文件不再有任何路由!现在在auth.js文件中执行相同的操作,其中包含与身份验证相关的所有内容,例如序列化和本地策略的设置,并从服务器文件中删除它们。确保添加依赖项并在同一位置调用服务器中的auth(app,db)
。确保routes(app, db)
auth(app, db)
之前有auth(app, db)
routes(app, db)
因为我们的注册路由取决于发起的护照!恭喜 - 您已经处于Advanced Node和Express的这一部分的末尾,并且有一些漂亮的代码可供展示!当您认为自己已经做对时,请提交您的页面。如果您遇到错误,可以在此处查看已完成项目的示例。 Instructions
Tests
tests:
- text: 存在的模块
testString: getUserInput => $.get(getUserInput('url')+ '/_api/server.js') .then(data => { assert.match(data, /require\s*\(('|")\.\/routes(\.js)?\1\)/gi, 'You should have required your new files'); assert.match(data, /mongo.connect[^]*routes/gi, 'Your new modules should be called after your connection to the database'); }, xhr => { throw new Error(xhr.statusText); })
Challenge Seed
Solution
// solution required
/section>