Skip to content

Commit

Permalink
redirect to custom domain
Browse files Browse the repository at this point in the history
  • Loading branch information
redraw committed Apr 24, 2024
1 parent 9d947cb commit 2dde0ca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ GET /passes/25544?lat=-34.9112212&lon=-57.9372988&limit=1 HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: satellites.fly.dev
Host: sat.terrestre.ar
User-Agent: HTTPie/1.0.3
```
Response example,
Expand Down
14 changes: 13 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
import json
import logging
from datetime import timedelta

from flask import Flask, Response, request, jsonify
from flask import Flask, Response, request, jsonify, redirect
from flask_cors import CORS
from flask_swagger_ui import get_swaggerui_blueprint
from marshmallow import ValidationError
Expand All @@ -19,6 +20,17 @@
CORS(api)


@api.before_request
def redirect_to_custom_domain():
custom_domain = os.getenv('CUSTOM_DOMAIN')
if (
custom_domain and
"FLY_APP_NAME" in os.environ and
request.host == f"{os.getenv('FLY_APP_NAME')}.fly.dev"
):
return redirect(f'https://{custom_domain}', code=301)


@api.route('/passes/<int:norad_id>')
def passes(norad_id):
try:
Expand Down

0 comments on commit 2dde0ca

Please sign in to comment.