我无法从这张票中获得结果来工作。我只是想创建更多模块化的代码块,并希望将路线和视图放在一起。我需要对这个进行健全性检查。
我无法使用相对路径获取获取 Jade 文件的路径(而且我不喜欢相对路径)Error: Failed to lookup view "../test/app"
:. 请帮忙 :)
Github:https ://github.com/franklovecchio/stackoverflow-13770206
文件夹结构:
.
│
├── package.json
├── public
│ └── lib
│ └── login
│ ├── 0.0.1
│ │ └── routes.coffee
│ └── test
│ └── app.jade
├── server.coffee
└── views
└── layout.jade
服务器.coffee
express = require('express')
http = require('http')
path = require('path')
app = express()
app.configure () ->
app.set 'port', process.env.PORT or 3000 # Give us the ability to specify port through command-line or external process.
app.set 'view options',
layout: false
app.set 'view engine', 'jade'
app.use express.favicon() # auto-gen
app.use express.logger('dev') # auto-gen
app.use express.bodyParser() # auto-gen
app.use express.methodOverride() # auto-gen
# Required by session() middleware
# Pass the secret for signed cookies
app.use express.cookieParser('The Stay Puft Marshmallow Man')
app.use app.router
app.use express.static(path.join(__dirname, '/public')) # Serve static assets.
app.configure 'development', ->
app.use express.errorHandler()
app.use require('readymade').middleware(root: '/public') # Make .coffee/.less serve as compiled .js/.css files.
# Routes
# ====================== Login ====================== #
login = require './public/lib/login/0.0.1/routes'
app.get '/', login.view
# ====================== /Login ====================== #
http.createServer(app).listen app.get('port'), ->
console.log 'Express server listening on port: ' + app.get('port')
路线.咖啡
exports.view = (req, res) ->
res.render '../test/app'
应用程序.jade
extends ../../../../views/layout
p login
布局.jade
doctype 5
html
head
title My title
block head
body
#content
block content
包.json
{
"name": "myapp",
"description": "modular",
"version": "0.0.1",
"private": true,
"dependencies": {
"express":"3.0.4",
"less":"",
"jade":"",
"markitup":"",
"readymade": ""
}
}