Git Product home page Git Product logo

dns-cloud-301's Introduction

dns-cloud-301

There are URL-forwarding services and there are DNS provider with custom additions to DNS. And there is JavaScript. To fully control how a subdomain is forwarded to some URL/webpage the cleanest and most change-resistant is to roll an own HTTP-based 301 redirect. This repo holds a Python3.[67] version as Google App Engine project.

Google Cloud App Engine

Create a project

Go to https://console.cloud.google.com/projectcreate and create a new project.

With the gcloud CLI SDK installed, run gcloud components update for good measure and enable the CLI API at https://console.cloud.google.com/flows/enableapi?apiid=cloudfunctions

Check if a gcloud account is currently authenticated with gloud auth list, if not use gloud auth login to open a browser login window. Settings can be persisted in a configuration file (on Ubuntu at ~/.config/gcloud/configurations/config_* (the file needs to contain only alphanumerical characters after the underscore _)) and that config can be activated with gcloud config configurations activate foobar (with foobar being the part after the underscore _).

Example of a config file:


/.config/gcloud/configurations/config_sunlightmapdev
[core]
account = [email protected]
project = foobar
disable_usage_reporting = True

[compute]
zone = europe-west3-b
region = europe-west3

[app]
promote_by_default = true

Changes to the current config file can be made with gcloud config set #...

The gcloud App Engine needs a "default" service set, deployment from this repo can be made with

cd ./application/physical/python
gcloud app deploy app-default.yaml

The code for a CNAME-based URL forwarder then lives in another service within this repo, deployment done with:

gcloud app deploy app-cname-cloud-301.yaml
gcloud app deploy dispatch.yaml

This deploys two services within the same gcloud App Engine project.

Custom domains can be configured at https://console.cloud.google.com/appengine/settings/domains?supportedpurview=project

Functionality

The code in ./application/physical/python checks incoming HTTP requests for a match against entries in a dictionary config["redirect_urls"] and conditionally redirects with status 301 to the value of that entry.

Location of the config file

The code handles three locations:

  • inline

  • googlestorage

  • an own endpoint, which in turn loads from inline or googlestorage

To use Google Cloud Storage, the bucket and the filename must be configured with storage_client_bucket or bucket_blob.

Python specifics

pip freeze will not add gunicorn to requirements.txt, so manually added as per https://cloud.google.com/appengine/docs/flexible/python/runtime#application_startup

dns-cloud-301's People

Contributors

cprima avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.