Change snippet url to display current host (#159)
* Change snippet url to current host * Change site.domain to host in page.js * Remove useless condition * Change hostname in email messages * Remove `hostname` command * Fix startup_checks.sh * Remove unused variable from startup_checks.py
This commit is contained in:
parent
2d5fbae279
commit
31cb616242
22
GUIDE.md
22
GUIDE.md
@ -41,15 +41,13 @@ Before continuing, please be sure to have the latest version of Docker installed
|
|||||||
|
|
||||||
5. Create an admin user by running `docker run --env-file=<your env file> milesmcc/shynet:latest ./manage.py registeradmin <your email>`. A temporary password will be printed to the console.
|
5. Create an admin user by running `docker run --env-file=<your env file> milesmcc/shynet:latest ./manage.py registeradmin <your email>`. A temporary password will be printed to the console.
|
||||||
|
|
||||||
6. Set the hostname of your Shynet instance by running `docker run --env-file=<your env file> milesmcc/shynet:latest ./manage.py hostname <your public hostname>`, where `<your public hostname>` is the _publicly accessible hostname_ of your instance, including port. This setting affects the URL that the tracking script sends its results to, so make sure it's correct. (Example hostnames: `shynet.example.com` or `example.com:8000`.)
|
6. Set the whitelabel of your Shynet instance by running `docker run --env-file=<your env file> milesmcc/shynet:latest ./manage.py whitelabel <whitelabel>`. While this setting doesn't affect any core operations of Shynet, it lets you rename Shynet to whatever you want. (Example whitelabels: `"My Shynet Instance"` or `"Acme Analytics"`.)
|
||||||
|
|
||||||
7. Set the whitelabel of your Shynet instance by running `docker run --env-file=<your env file> milesmcc/shynet:latest ./manage.py whitelabel <whitelabel>`. While this setting doesn't affect any core operations of Shynet, it lets you rename Shynet to whatever you want. (Example whitelabels: `"My Shynet Instance"` or `"Acme Analytics"`.)
|
7. Launch your webserver by running `docker run --env-file=<your env file> milesmcc/shynet:latest`. You may need to bind Docker's port 8080 (where Shynet runs) to your local port 80 (http); this can be done using the flag `-p 80:8080` after `run`. Visit your service's homepage, and verify everything looks right! You should see a login prompt. Log in with the credentials from step 5. You'll probably be prompted to "confirm your email"—if you haven't set up an email server, the confirmation email will be printed to the console instead.
|
||||||
|
|
||||||
8. Launch your webserver by running `docker run --env-file=<your env file> milesmcc/shynet:latest`. You may need to bind Docker's port 8080 (where Shynet runs) to your local port 80 (http); this can be done using the flag `-p 80:8080` after `run`. Visit your service's homepage, and verify everything looks right! You should see a login prompt. Log in with the credentials from step 5. You'll probably be prompted to "confirm your email"—if you haven't set up an email server, the confirmation email will be printed to the console instead.
|
8. Create a service by clicking "+ Create Service" in the top right hand corner. Fill out the options as appropriate. Once you're done, press "create" and you'll be redirected to your new service's analytics page.
|
||||||
|
|
||||||
9. Create a service by clicking "+ Create Service" in the top right hand corner. Fill out the options as appropriate. Once you're done, press "create" and you'll be redirected to your new service's analytics page.
|
9. Finally, click on "Manage" in the top right of the service's page to get the tracking script code. Inject this script on all pages you'd like the service to track.
|
||||||
|
|
||||||
10. Finally, click on "Manage" in the top right of the service's page to get the tracking script code. Inject this script on all pages you'd like the service to track.
|
|
||||||
|
|
||||||
|
|
||||||
### Basic Installation with Docker Compose
|
### Basic Installation with Docker Compose
|
||||||
@ -66,9 +64,7 @@ Before continuing, please be sure to have the latest version of Docker installed
|
|||||||
|
|
||||||
5. Create an admin user by running `docker exec -it shynet_main ./manage.py registeradmin <your email>`. A temporary password will be printed to the console.
|
5. Create an admin user by running `docker exec -it shynet_main ./manage.py registeradmin <your email>`. A temporary password will be printed to the console.
|
||||||
|
|
||||||
6. Set the hostname of your Shynet instance by running `docker exec -it shynet_main ./manage.py hostname <your public hostname>`, where `<your public hostname>` is the same as the hostname you set in step 3. This setting affects the URL that the tracking script sends its results to, so make sure it's correct. (Example hostnames: shynet.example.com or example.com:8000.)
|
6. Set the whitelabel of your Shynet instance by running `docker exec -it shynet_main ./manage.py whitelabel <whitelabel>`. While this setting doesn't affect any core operations of Shynet, it lets you rename Shynet to whatever you want. (Example whitelabels: "My Shynet Instance" or "Acme Analytics".)
|
||||||
|
|
||||||
7. Set the whitelabel of your Shynet instance by running `docker exec -it shynet_main ./manage.py whitelabel <whitelabel>`. While this setting doesn't affect any core operations of Shynet, it lets you rename Shynet to whatever you want. (Example whitelabels: "My Shynet Instance" or "Acme Analytics".)
|
|
||||||
|
|
||||||
Your site should now be accessible at `http://hostname:port`. Now you can follow steps 9-10 of the [Basic Installation](#basic-installation) guide above to get Shynet integrated on your sites.
|
Your site should now be accessible at `http://hostname:port`. Now you can follow steps 9-10 of the [Basic Installation](#basic-installation) guide above to get Shynet integrated on your sites.
|
||||||
|
|
||||||
@ -78,11 +74,10 @@ You may wish to deploy Shynet on Heroku. Note that Heroku's free offerings (name
|
|||||||
|
|
||||||
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/milesmcc/shynet/tree/master)
|
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/milesmcc/shynet/tree/master)
|
||||||
|
|
||||||
Once you deploy, you'll need to setup an admin user, whitelabel, and hostname before you can use Shynet. Do that with the following commands:
|
Once you deploy, you'll need to setup an admin user and whitelabel before you can use Shynet. Do that with the following commands:
|
||||||
|
|
||||||
1. `heroku run --app=<your app> ./manage.py registeradmin <your email>`
|
1. `heroku run --app=<your app> ./manage.py registeradmin <your email>`
|
||||||
2. `heroku run --app=<your app> ./manage.py hostname <the hostname where you will run Shynet>`
|
2. `heroku run --app=<your app> ./manage.py whitelabel "<your Shynet instance's name>"`
|
||||||
3. `heroku run --app=<your app> ./manage.py whitelabel "<your Shynet instance's name>"`
|
|
||||||
|
|
||||||
## Render
|
## Render
|
||||||
|
|
||||||
@ -93,8 +88,7 @@ Once you deploy, you'll need to setup an admin user, whitelabel, and hostname be
|
|||||||
Once your deploy has completed, use the **Render Shell** to configure your app:
|
Once your deploy has completed, use the **Render Shell** to configure your app:
|
||||||
|
|
||||||
1. Set your email: `./manage.py registeradmin your-email@example.com`
|
1. Set your email: `./manage.py registeradmin your-email@example.com`
|
||||||
1. Add your onrender.com domain: `./manage.py hostname your-shynet-domain.onrender.com`
|
2. Set your whitelabel: `./manage.py whitelabel "Your Shynet Instance Name"`
|
||||||
1. Set your whitelabel: `./manage.py whitelabel "Your Shynet Instance Name"`
|
|
||||||
|
|
||||||
See the [Render docs](https://render.com/docs/deploy-shynet) for more information on deploying your application on Render.
|
See the [Render docs](https://render.com/docs/deploy-shynet) for more information on deploying your application on Render.
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ var Shynet = {
|
|||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.open(
|
xhr.open(
|
||||||
"POST",
|
"POST",
|
||||||
"{{protocol}}://{{request.site.domain|default:request.META.HTTP_HOST}}{{endpoint}}",
|
"{{protocol}}://{{request.get_host}}{{endpoint}}",
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
xhr.setRequestHeader("Content-Type", "application/json");
|
xhr.setRequestHeader("Content-Type", "application/json");
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
import traceback
|
|
||||||
import uuid
|
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
from django.contrib.sites.models import Site
|
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
|
||||||
from django.utils.crypto import get_random_string
|
|
||||||
|
|
||||||
from core.models import User
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
|
||||||
help = "Configures the Shynet hostname"
|
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
|
||||||
parser.add_argument(
|
|
||||||
"hostname",
|
|
||||||
type=str,
|
|
||||||
)
|
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
|
||||||
site = Site.objects.get(pk=settings.SITE_ID)
|
|
||||||
site.domain = options.get("hostname")
|
|
||||||
if options.get("hostname").lower().startswith("http"):
|
|
||||||
self.stdout.write(
|
|
||||||
self.style.WARNING(
|
|
||||||
f"Warning: the hostname '{options.get('hostname')}' starts with `http`. You almost certainly don't want this. The hostname is supposed to be the raw domain name of your Shynet instance, without `http://` or `https://`. For example, if your Shynet instance will eventually be hosted at `https://analytics.example.com`, the hostname should be `analytics.example.com`."
|
|
||||||
)
|
|
||||||
)
|
|
||||||
site.save()
|
|
||||||
self.stdout.write(
|
|
||||||
self.style.SUCCESS(
|
|
||||||
f"Successfully set the hostname to '{options.get('hostname')}'"
|
|
||||||
)
|
|
||||||
)
|
|
@ -35,15 +35,9 @@ class Command(BaseCommand):
|
|||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
migration = self.check_migrations()
|
migration = self.check_migrations()
|
||||||
|
|
||||||
admin, hostname, whitelabel = [True] * 3
|
admin, whitelabel = [True] * 2
|
||||||
if not migration:
|
if not migration:
|
||||||
admin = not User.objects.all().exists()
|
admin = not User.objects.all().exists()
|
||||||
hostname = (
|
|
||||||
not Site.objects.filter(domain__isnull=False)
|
|
||||||
.exclude(domain__exact="")
|
|
||||||
.exclude(domain__exact="example.com")
|
|
||||||
.exists()
|
|
||||||
)
|
|
||||||
whitelabel = (
|
whitelabel = (
|
||||||
not Site.objects.filter(name__isnull=False)
|
not Site.objects.filter(name__isnull=False)
|
||||||
.exclude(name__exact="")
|
.exclude(name__exact="")
|
||||||
@ -52,5 +46,5 @@ class Command(BaseCommand):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.stdout.write(
|
self.stdout.write(
|
||||||
self.style.SUCCESS(f"{migration} {admin} {hostname} {whitelabel}")
|
self.style.SUCCESS(f"{migration} {admin} {whitelabel}")
|
||||||
)
|
)
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
{% load account %}{% user_display user as user_display %}{% load i18n %}{% autoescape off %}{% blocktrans with site_name=current_site.name site_domain=current_site.domain %}Hi there,
|
{% load account %}{% user_display user as user_display %}{% load i18n %}{% autoescape off %}{% blocktrans with site_name=current_site.name site_domain=request.get_host %}Hi there,
|
||||||
|
|
||||||
You're receiving this email because {{ user_display }} has listed this email as a valid contact address for their account.
|
You're receiving this email because {{ user_display }} has listed this email as a valid contact address for their account.
|
||||||
|
|
||||||
To confirm this is correct, go to {{ activate_url }}
|
To confirm this is correct, go to {{ activate_url }}
|
||||||
{% endblocktrans %}
|
{% endblocktrans %}
|
||||||
{% blocktrans with site_name=current_site.name site_domain=current_site.domain %}Thank you,
|
{% blocktrans with site_name=current_site.name site_domain=request.get_host %}Thank you,
|
||||||
{{ site_name }}
|
{{ site_name }}
|
||||||
{% endblocktrans %}
|
{% endblocktrans %}
|
||||||
{% endautoescape %}
|
{% endautoescape %}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{% load i18n %}{% autoescape off %}{% blocktrans with site_name=current_site.name site_domain=current_site.domain %}Hi there,
|
{% load i18n %}{% autoescape off %}{% blocktrans with site_name=current_site.name site_domain=request.get_host %}Hi there,
|
||||||
|
|
||||||
You're receiving this email because you or someone else has requested a password for your account.
|
You're receiving this email because you or someone else has requested a password for your account.
|
||||||
|
|
||||||
@ -6,7 +6,7 @@ This message can be safely ignored if you did not request a password reset. Clic
|
|||||||
|
|
||||||
{{ password_reset_url }}
|
{{ password_reset_url }}
|
||||||
|
|
||||||
{% blocktrans with site_name=current_site.name site_domain=current_site.domain %}Thank you,
|
{% blocktrans with site_name=current_site.name site_domain=request.get_host %}Thank you,
|
||||||
{{ site_name }}
|
{{ site_name }}
|
||||||
{% endblocktrans %}
|
{% endblocktrans %}
|
||||||
{% endautoescape %}
|
{% endautoescape %}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<div class="card ~neutral !high font-mono text-sm whitespace-pre-wrap break-all">{% filter force_escape %}<noscript>
|
<div class="card ~neutral !high font-mono text-sm whitespace-pre-wrap break-all">{% filter force_escape %}<noscript>
|
||||||
<img src="{{script_protocol}}{{request.site.domain}}{% url 'ingress:endpoint_pixel' object.uuid %}">
|
<img src="{{script_protocol}}{{request.get_host}}{% url 'ingress:endpoint_pixel' object.uuid %}">
|
||||||
</noscript>
|
</noscript>
|
||||||
<script defer src="{{script_protocol}}{{request.site.domain}}{% url 'ingress:endpoint_script' object.uuid %}"></script>{% endfilter %}
|
<script defer src="{{script_protocol}}{{request.get_host}}{% url 'ingress:endpoint_script' object.uuid %}"></script>{% endfilter %}
|
||||||
</div>
|
</div>
|
@ -16,9 +16,6 @@ if [[ ${startup_results[1]} == True ]]; then
|
|||||||
echo "Warning: no admin user available. Consult docs for instructions."
|
echo "Warning: no admin user available. Consult docs for instructions."
|
||||||
fi
|
fi
|
||||||
if [[ ${startup_results[2]} == True ]]; then
|
if [[ ${startup_results[2]} == True ]]; then
|
||||||
echo "Warning: Shynet's hostname is not set. The script won't work correctly. Consult docs for instructions."
|
|
||||||
fi
|
|
||||||
if [[ ${startup_results[3]} == True ]]; then
|
|
||||||
echo "Warning: Shynet's whitelabel is not set. Consult docs for instructions."
|
echo "Warning: Shynet's whitelabel is not set. Consult docs for instructions."
|
||||||
fi
|
fi
|
||||||
echo "Startup checks complete!"
|
echo "Startup checks complete!"
|
||||||
|
Loading…
Reference in New Issue
Block a user