Custom go/ links that are setup through a simple python HTTPs server with configurations with Alfred!
Inspired by golinks and go-alfred
Required to serve our https server, store in same directory as the repository
openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
This is your database file with the following format:
{
"shortlink": "https://example.com"
}
There is a mapping.json.template
file in the repository that you can rename to mapping.json
to get started
Import the setup/go.alfredworkflow package into alfred, you will need to purchase the powerpack
To setup https://go/
to work for you you will need to add a loopback from your local IP address to the go domain, which can be done by adding the line below to your /etc/hosts
file
127.0.0.1 go
Notes:
- The server binds to port 443 (
https
) and listens for requests, and thus needs to be started withsudo
- The
&
at the end is to start the server in the background - The
--goserver
argument adds as an easy way to search for the process usingps -a | grep goserver
for when you actually want to kill it (you will need to usesudo kill <pid>
to actually kill the process) - The automatic start workflow using
launchd
is documented at the bottom as an optional alternative to starting the server manually
sudo python3 main.py --goserver &
If test
is your short keyword, and https://example.com
is your destination link then you can setup the mapping by going into alfred and typing new
and then test
which is your shortlink and then your domain https://example.com
and then pressing enter, it will automatically navigate you to the URL below https://go/new?test=https://example.com, and the resulting webpage should confirm that the mapping has been added
To open a shortlink that you have created eg: test
from above, all you have to do is open alfred type go
and then test
which is your shortlink and then pressing enter and the browser should open the destination link
If test
is your short keyword, you can delete the mapping by going into alfred and typing delete
and then test
which is your shortlink and then pressing enter, it will automatically navigate you to the URL below https://go/delete?test=delete and the resulting webpage should confirm that the mapping has been deleted
If test
is your short keyword, and https://example.com
is your destination link then you can setup the mapping by navigating to https://go/new?test=https://example.com and the resulting webpage should confirm that the mapping has been added
If you are trying to open a shortlink that you have created eg: test
from above, all you have to do is navigate to https://go/test
and the browser will open the destination link
- There is a metrics logging file
metrics.csv
that logs the visit time of each shortlink with its corresponding destination domain (Refermetrics.csv.template
for format example) - You can configure the port, the mapping file, the metrics file, the prefix to create a new domain, as well as the path of the certificate file all through the
config.ini
file - This service can also be setup as a
launchd
service using the setup/com.adityaarora.golinks.plist file as reference. Ensure you change theWorkingDirectory
as well as theStandardOutPath
andStandardErrorPath
. After that simply store the file in/Library/LaunchDaemons
and then runsudo launchctl load /Library/LaunchDaemons/com.adityaarora.golinks.plist
to load the service. The service should be started automatically, and if there are any issues you can inspect the log files you put in.