[英]Node js, no response returned while using connect-memcached
嗨,我正在使用compoundjs和connect-memcached。 以下是我的envirionment.js文件中的內容:
module.exports = function (compound) {
var express = require('express');
var MemcachedStore = require('connect-memcached')(express);
var app = compound.app;
require('./mongoose').init(compound);
app.configure(function(){
app.use(compound.assetsCompiler.init());
app.use(express.static(app.root + '/public', { maxAge: 86400000 }));
app.set('view engine', 'ejs');
app.set('view options', { complexNames: true });
app.set('jsDirectory', '/javascripts/');
app.set('cssDirectory', '/stylesheets/');
app.set('cssEngine', 'stylus');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.favicon());
app.use(express.logger());
app.use(express.cookieParser());
app.use(express.session({secret: 'AuthenticationSecret', store: new MemcachedStore}));
app.use(app.router);
}); };
當我通過提供以下命令啟動服務器時:
NODE_ENV=production node .
它開始很好,我得到:
MemcachedStore initialized for servers: 127.0.0.1:11211
AssetsCompiler Precompiling assets: coffee, styl
Compound server listening on 0.0.0.0:3000 within production environment
當我通過瀏覽器請求時,我沒有收到任何回復。
以下是我的routes.js文件內容:
exports.routes = function (map) {
map.get('api/yourname','names#index')
}
在我的名字控制器中:
load('application');
action('index', function(req, res) {
send({"name": "Senthil"});
});
PS:如果我評論使用connect-memcached的代碼並通過瀏覽器請求,我得到了回復。
感謝您的幫助。
嘗試在new MemcacheStore
之后添加括號和配置,使其看起來像這樣:
app.use(express.session({
secret: 'AuthenticationSecret',
store: new MemcachedStore({
hosts: [ '127.0.0.1:11212' ]
})
}));
(假設您的memcache服務器位於localhost:11212 - 如果沒有,則將主機行更改為服務器的主機名或IP。)
對於會話,您需要一個密鑰。 否則,您將收到此錯誤。
錯誤:會話需要
secret
選項
我假設你沒有看到錯誤,因為你在生產環境中運行。 像這樣添加一個密鑰:
app.use(express.session({
store: new MemcachedStore,
secret: 'secret_key'
}));
由於您運行的是localhost,因此無需指定主機或端口。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.