2012-12-11 1 views
0

Express 3으로 업그레이드 한 후 connect-flash 구현의 "즐거움"을 경험하고 작동 시켰습니다.플래시는 Express 3, connect-flash 및 everyauth로 정의되지 않았습니다.

var flash = require('connect-flash'); 

app.use(flash()); 

app.use(function (req, res, next) { 
    res.locals.everyauth.user = req.user; 
    res.locals.user = req.user; 
    res.locals.flash = req.flash(); 
    next(); 
}); 

내가 내 옥 레이아웃 템플릿 플래시 경고 표시 (모든 페이지에서 사용을하고 flash.info에 대한 비슷한 라인, flash.warning 등이)이 같은을 :

나는 다음과 같이 구현 : 나는 "플래시가 정의되지 않은"오류가 발생하는 경우

- if ('undefined' !== typeof flash.error && flash.error.length) 
    - each msg in flash.error 
     div.error= msg 

모든 내가 표현을 통해 내/로그인 및/회원 가입 페이지를 렌더링 할 때를 제외하고 잘. 어떤 아이디어?

+0

아무 것도 추가하지 않은 것처럼 보입니다. – chovy

+0

나는'res.locals.flash = req.flash; '이어야한다고 생각하고있다. –

+0

'req.flash ('info ','this is a flash message ');'기쁨이 없다. 'res.locals.flash = req.flash; '는'req.flash()'를 사용하는 것과 똑같이 동작합니다 (즉, 모든 페이지는 everyauth 로그인과 등록 페이지를 제외하고 모두 작동합니다). – pat

답변

1

글쎄, 꽤 아니지만, 이것에 대한 해결 방법을 찾았습니다. 기본적으로, 플래시 메시지를 처리하는 내 특급 템플릿의 블록에 문 경우 첫 번째 추가 한 : 그런 다음

- if (flash !== null) 
    - if ('undefined' !== typeof flash.error && flash.error.length) 
     - each msg in flash.error 
      div.error= msg 

    - if ('undefined' !== typeof flash.warning && flash.warning.length) 
     - each msg in flash.warning 
      div.warning= msg 

    - if ('undefined' !== typeof flash.info && flash.info.length) 
     - each msg in flash.info 
      div.info= msg 

    - if ('undefined' !== typeof flash.success && flash.success.length) 
     - each msg in flash.success 
      div.success= msg 

를,이 같은 null로 플래시를 설정 everyauth의 페이지 렌더링 문에 지역 변수를 추가 내가 말했듯이 꽤되지,

.registerView('register.jade') 
    .registerLocals({ 
     title: 'Hi there, I am a register page', 
     flash: null 
    }) 

을, 그러나 그것은 작동하는 것 같군 : (당신은 등록 및 로그인 페이지 하나가 필요합니다).

관련 문제