سؤال

Our users play our Django game directly via our domain, cnamed to herokuapp.com. We request our assets via http.

We want to add our game to facebook, which requires using https. Heroku can handle this.

Using https requests: our game works on facebook but fails to load assets when accessed via our cnamed domain.

Can we make our game use https when played via facebook and http when played from our domain? What code must we add to settings.py?

We've tried this code in settings.py but it didn't work

Option 1:

import socket
if socket.gethostname().startswith('app'):
  LIVEHOST = True
else:
  LIVEHOST = False

if LIVEHOST:
  STATIC_URL = "https://d******1.cloudfront.net/"
else:
  STATIC_URL = "http://d******1.cloudfront.net/"

Option 2:

import socket
if socket.gethostname().startswith('edge'):
  LIVEHOST = True
else:
  LIVEHOST = False

if LIVEHOST:
  STATIC_URL = "https://d******1.cloudfront.net/"
else:
  STATIC_URL = "http://d******1.cloudfront.net/"
هل كانت مفيدة؟

المحلول

You could use protocol relative urls to save yourself from the pain of worrying about the protocol to use.

So the settings would look like:

STATIC_URL = "//d******1.cloudfront.net/"

and you can safely get rid of all the computation logic in your code snippet.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top