我有一个简单的快速应用程序,其app.js代码如下所示:
var env = process.env.NODE_ENV || "development"
var packageJson = require("../package.json")
var path = require("path")
var express = require("express")
var csurf = require("csurf")
var cookieSession = require('cookie-session')
var bodyParser = require('body-parser')
console.log("Loading App in "+env +" mode")
global.App={
app : express(),
port : process.env.PORT || 3000,
version : packageJson.version,
name : packageJson.name,
mailSender : process.env.MAIL_SENDER || '"SchoolManagement"<no-reply@schoolManagement.com>',
root : path.join(__dirname,'..'),
urls : {
root: process.env.ROOT_URL
},
appPath : function(path){
return this.root+'/'+path
},
require : function(path){
return require(this.appPath(path))
},
env : env,
start : function (path) {
if(!this.started){
this.started=true
this.app.listen(this.port)
console.log("Running App Version: "+this.version+" On "+this.env+" On port: "+this.port)
}
},
model: function(path){
return this.require("app/models/"+path)
},
util : function(path){
return this.require("app/utils/"+path)
},
route : function(path){
return this.require("app/routes/"+path)
}
}
App.app.set('views','../views');
App.app.set('view engine','jade');
App.app.set('view options', {
layout: false
});
App.app.use(bodyParser.json)
App.app.use(bodyParser.urlencoded({extended:true}));
App.app.use(require('method-override'))
App.app.use(require('cookie-parser'))
App.app.use(express.Router())
App.app.use(cookieSession({secret: "it'sasecrettoeverybody", key: "session"}))
App.app.use(express.static(App.appPath('public')))
App.require("config/routes")(App.app)
App.require('config/database')(process.env.DATABASE_URL || 'mongodb://localhost/nodeslash_' + App.env)
我的routes.js如下:
module.exports = function(app){
var homeRoutes = App.route("homeRoutes")
app.get('/',homeRoutes.home)
var usersRoutes = App.route("userRoutes")
app.get("/sign_up",usersRoutes.new)
app.post("/sign_up",usersRoutes.create)
var sessionRoutes = App.route("sessionsRoutes")
app.get("/sign_in",sessionRoutes.new)
app.post("/sign_in",sessionRoutes.create)
}
但是当我运行server.js文件并在浏览器上打开localhost:3000时, 请求被等待localhost:3000而且我没有得到任何响应,我也有'/'get请求的正确映射,下面是请求映射:
exports.home = function(req,res){
res.render('home/home',{})
}
我在'home'目录中也有jade文件,其内容如下:
extends ../layouts/home
block content
h1 Web's Premiere Browser Game
h2 Message from Borgoroth
我是node.js和jade的新手,我无法解决出错的问题,我也没有在控制台看到任何日志,有人可以帮忙。