2016-04-09 92 views
1

我在登錄頁面上使用背景圖像,但在部署到heroku時未獲取加載。它在Localhost上運行良好。當我打開調試器窗口並在瀏覽器中打開圖像URL時,它將重定向到登錄屏幕。如何避免在登錄屏幕上驗證背景圖像的身份驗證。節點。在登錄屏幕上繞過圖像驗證

模板代碼中的登錄是如下:

div(class="container" style="background-image:url(../images/school-wallpaper.jpg);height:650px;width:100%") 
     form(class="form-signin" method="post") 
      h2(class="form-signin-heading") Please sign in 
       label(for="inputEmail", class="sr-only") 
        Email address 
       input(type="email", id="inputEmail", name="email" class="form-control", placeholder="Email address", required, autofocus) 
       label(for="inputPassword", class="sr-only") Password 
       input(type="password", id="inputPassword", name= "password", class="form-control", placeholder="Password", required) 
       br 
       button(class="btn btn-lg btn-primary btn-block", type="submit") Sign in 
       #error 
        if error 
         label.error #{error} 

和服務器端實現:

app.use(function(req, res, next) { 
    res.setHeader("Access-Control-Allow-Methods", "POST, PUT, OPTIONS, DELETE, GET"); 
    res.header("Access-Control-Allow-Origin", "http://localhost"); 
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); 
    if(req.url.indexOf("/login")==0) 
     next() 
    else{ 
     if(req.session.userProile){ 
     next(); 
     } 
     else{ 
     res.redirect('/login'); 
     } 
    } 
    }); 

回答

0

你的錯誤是,你硬編碼Access-Control-Allow-Origin頭,在這裏:

res.header("Access-Control-Allow-Origin", "http://localhost"); 

一旦部署到heroku,主機不是localhost任何更多。我建議你將你的主機名存放在一個環境變量中,這在生產或開發時會有所不同。您可以使用例如dotenv模塊來使此過程更容易。

+0

感謝噸....它的工作原理。 –