次のエラーが発生します:
/Users/nblavoie/Desktop/HotPie/HotPie/apps/authentication/routes.coffee:6
app.get('/login', function(req, res) {
^
ReferenceError: app is not defined
at Object.<anonymous> (/Users/nblavoie/Desktop/HotPie/HotPie/apps/authentication/routes.coffee:6:3)
at Object.<anonymous> (/Users/nblavoie/Desktop/HotPie/HotPie/apps/authentication/routes.coffee:15:4)
at Module._compile (module.js:449:26)
at Object.require.extensions..coffee (/Users/nblavoie/Desktop/HotPie/HotPie/node_modules/coffee-script/lib/coffee-script/coffee-script.js:22:21)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/Users/nblavoie/Desktop/HotPie/HotPie/app.js:31:1)
at Module._compile (module.js:449:26)
(app)変数を次のrequireに渡そうとしている間:
/**
* Module dependencies.
*/
require('coffee-script');
var express = require('express')
, http = require('http')
, path = require('path');
var app = express();
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
app.configure('development', function(){
app.use(express.errorHandler());
});
// Routes
**require('./apps/authentication/routes')(app);**
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
次のファイルのapp変数を使用します。
routes = (app) ->
app.get '/login', (req, res) ->
res.render 'views/login',
title: 'Login'
stylesheet: 'login'
module.exports = routes
可変スコープはJSファイルごとに異なることを私は知っています。しかし、なぜ次の行があります:
require('./apps/authentication/routes')(app);
アプリ変数を渡さないのですか?