2016-07-26 15 views
0

Ich habe eine Express-App-Setup, aber ich kann nicht herausfinden, wie man es richtig routen. Im Moment habe ich dies in app.js:Express Routing - 404 Fehler beim Routing nach/secrets, was fehlt mir

var secrets = require('./routes/secrets'); 
var app = express(); 

app.use('secrets', secrets); 

Die folgenden in /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; 

Die Datei /views/secrets.jade enthält den folgenden Code:

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..." 

Aber im Moment bekomme ich nur einen 404 Fehler, wenn ich/Geheimnisse in den Browser nach der Stamm-URL eingeben. Kann mir jemand sagen, wie ich das anders angehen kann, damit ich eine erfolgreiche GET-Anfrage registrieren und die Seite richtig bedienen kann?

+0

Es könnte in '/ Routen/secrets.js' wegen eines Syntaxfehler werden abstürzt, sollte es sein' res.render ("Geheimnisse ', {Titel:' Color Hack v1.1}); ' – DrakaSAN

+0

@DrakaSAN Danke. Ich werde das ändern, wenn es hilft:) ... nein; Ich habe das direkt in der Akte. Nur ein Übertragungsfehler meinerseits da, sorry DranSAN: /. –

Antwort

1

zuerst ein ‚/‘ auf Ihre Anfrage url in app.js hinzufügen: app.use('/secrets', secrets)

Jetzt noch Sie definieren als GET zu verwenden „/ Geheimnisse/Geheimnisse“, weil die Einstellung des Routers Anfrage URL anfügt aus app.js.

Ändern Sie die URL für den Router nur / wie

router.get('/', function(req, res, next) {}); 
+0

Danke Hardi. Ich habe es versucht, aber es funktioniert immer noch nicht. Gibt es eine Möglichkeit, zu verfolgen, was tatsächlich im Browser angefordert wird? Ich benutze Iceweasel, das ist eigentlich Firefox, denke ich. –

+0

Vergiss es. Ich habe den Server neu gestartet und jetzt funktioniert es gut. Vielen Dank! –