【发布时间】:2016-07-26 16:37:12
【问题描述】:
我有一个快速应用设置,但我不知道如何使其正确路由。目前我在 app.js 中有这个:
var secrets = require('./routes/secrets');
var app = express();
app.use('secrets', secrets);
/routes/secrets.js 中的以下内容
var express = require('express');
var router = express.Router();
/* GET 'secrets' */
router.get('/secrets', function(req, res, next) {
res.render('secrets', { title: 'Colour Hack v1.1' });
});
module.exports = router;
文件/views/secrets.jade 包含以下代码:
extends layout
block content
h1 A Very Green Affair
p It began at a Green Party hustings. I was wearing a beige trenchcoat, set off perfectly by an exquisitely cut Fedora, tailored by the finest vegan outfitters a party councilor's allowance can buy. We locked eyes over the pay-what-you-like FoodCycle buffet and I knew right then something special was about to occur. Amelia Womack wore a pant-suit and has a really nice hair-style. Once she noticed me she approached immediately.
p "Hi Amy."
p She said, though it appeared as if the name was somehow unfamiliar to her, and she looked into my eyes with the sort of intensity you might expect of a fawn who's just single-handedly decimated a pack of ravaging wolves and has rounded on the ring-leader who has unexpectedly turned out to be another fawn with particularly big teeth and wolf-like fur who had managed to convince the wolves it was one of them.
p "It's strange I should run into you as I was just thinking about that... policy suggestion you made."
p Amelia said the word 'that' with an odd intonation, so it seemed almost as if she were thinking about something other than the policy document. Something secret.
p "The cat policy," I replied, my words sounding both artful and powerful as I spoke them, and considered her choice of blusher, which seemed a particularly deep red, so that it underscored her already stunning features with a power and authority that lost nothing of femininity. Amelia noticed a kind of damp feeling and wondered if she should have brought a change of underwear but she carried on in a business-like, official sort of way which also seemed to tred a strangely fine line between school-girlish and teacherly.
p "Yes, Amy, the cat policy. We really need to talk about the cats, don't we..."
但目前,当我在浏览器的根 URL 之后键入 /secrets 时,我收到了 404 错误。谁能告诉我如何以不同的方式处理此问题,以便我注册成功的 GET 请求并正确提供页面?
【问题讨论】:
-
它可能是因为
/routes/secrets.js中的语法错误而崩溃,它应该是res.render('secrets', {title: 'Colour Hack v1.1}); -
@DrakaSAN 谢谢。我会改变它,看看它是否有帮助:)......不;我在文件中有这个权利。只是我的一个转录错误,抱歉 DranSAN :/.
标签: javascript node.js templates express http-status-code-404