SORU
25 AĞUSTOS 2011, PERŞEMBE


Heroku NodeJS https ssl zorla için http yeniden yönlendirme

Ve https ile düğümde express ile heroku üzerinde çalışan bir uygulama var. Nasıl heroku üzerinde nodejs ile https yönlendirme zorlamak için protokol bulabilirim ki?

Benim app sadece basit bir http server, (henüz) heroku istekleri https gönderiyor fark etmez:

/* Heroku provides the port they want you on in this environment variable (hint: it's not 80) */
app.listen(process.env.PORT || 3000);

CEVAP
31 AĞUSTOS 2011, ÇARŞAMBA


Cevap 'x-forward-proto' Heroku bu proxy zımbırtı filan gibi öne geçer. bu başlık kullanmaktır (yan not: kullanışlı, check them out) olabilecek birkaç diğer x - değişkenler de geçerler.

Benim kod:

/* At the top, with other redirect methods before other routes */
app.get('*',function(req,res,next){
  if(req.headers['x-forwarded-proto']!='https')
    res.redirect('https://mypreferreddomain.com' req.url)
  else
    next() /* Continue to other routes if we're not redirecting */
})

Teşekkürler Brandon, sadece ben kendi soruma cevap vereyim olmaz 6 saat gecikme o şeyi bekliyordu.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Abbeydabby0277's channel

    Abbeydabby02

    9 ŞUBAT 2012
  • BlackBoxTV

    BlackBoxTV

    7 Mayıs 2007
  • Majestic Casual

    Majestic Cas

    28 NİSAN 2012