{"id":16967554,"url":"https://github.com/highoncarbs/shorty","last_synced_at":"2025-03-17T08:37:47.305Z","repository":{"id":44146984,"uuid":"94975814","full_name":"highoncarbs/shorty","owner":"highoncarbs","description":":link: A URL shortening service built using Flask and MySQL","archived":false,"fork":false,"pushed_at":"2023-05-01T20:14:21.000Z","size":353,"stargazers_count":108,"open_issues_count":3,"forks_count":26,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-16T10:12:52.573Z","etag":null,"topics":["analytics","aws","database","ec2-instance","flask","mysql","nginx","python","url-shortener","urlshortener","uwsgi","webapp"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/highoncarbs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-21T07:27:41.000Z","updated_at":"2025-03-03T09:03:31.000Z","dependencies_parsed_at":"2024-10-27T12:47:05.466Z","dependency_job_id":null,"html_url":"https://github.com/highoncarbs/shorty","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/highoncarbs%2Fshorty","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/highoncarbs%2Fshorty/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/highoncarbs%2Fshorty/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/highoncarbs%2Fshorty/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/highoncarbs","download_url":"https://codeload.github.com/highoncarbs/shorty/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244001630,"owners_count":20381805,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analytics","aws","database","ec2-instance","flask","mysql","nginx","python","url-shortener","urlshortener","uwsgi","webapp"],"created_at":"2024-10-14T00:08:59.761Z","updated_at":"2025-03-17T08:37:47.287Z","avatar_url":"https://github.com/highoncarbs.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"#  :link: Shorty\n\n\u003e A self-hosted URL shortening service built using Flask \u0026 Mysql. \n\n![Demo image of Shorty](./desc/hero_final.gif)\n\n\n## :tada: Surprise : Click Analytics \n\nTracking for Operating system and platform used to access the link is available.\n\n\n![Demo image for analytics](./desc/ana_demo.gif)\n\n## Getting Started\n\nClone or download this repository.\n\n```\ngit clone https://github.com/PadamSethia/shorty.git\n\ncd shorty/\n\npython ./app.py\n```\n\n## Prerequisites\n\nThis project requires Flask and MySQL . \nAnd MySQLdb python module for connection.\nYou can install it using the following commands . \n\n```\npip install flask\n\n```\nFor mysql as backend\n\n```\nsudo apt install mysql-server\n\nsudo apt-get install libmysqlclient-dev\n\npip install MySQL-python\n```\n\nNow run the following command to create the MySQL table \n\n```\npython ./create_table.py\n```\n\nConfigure the MySQL database credentials in `config.py`\nSet the host , user , password and database name for MySQL connection.\n\nAlso under MySQL shell set \n\n```\nset autocommit = 0\n```\n\nThis takes care of the concurrency issue.\n\n## RESTful API\n\n\n`POST /api/v1/shorten` with form data `url=https://github.com/PadamSethia` , `custom=blah` \u0026 `tag=test` custom and tag are optional.\n\n\n```json\n{\n    \"custom\": \"blah\",\n    \"long_url\": \"https://github.com/PadamSethia\",\n    \"short_url\": \"http://localhost:5454/blah\",\n    \"tag\": \"test\" \n}\n```\n\n\n`GET /api/v1/expand/` with form data `custom=blah`\n\n\n```json\n{\n    \"click_browser\": {\n        \"CHROME\": 0,\n        \"FIREFOX\": 0,\n        \"OTHER_BROWSER\": 0,\n        \"SAFARI\": 0\n    },\n    \"click_platform\": {\n        \"ANDROID\": 0,\n        \"IOS\": 0,\n        \"LINUX\": 0,\n        \"MAC\": 0,\n        \"OTHER_PLATFORM\": 0,\n        \"WINDOWS\": 0\n    },\n    \"clicks\": 0,\n    \"custom\": \"blah\",\n    \"long_url\": \"http://github.com/PadamSethia\",\n    \"tag\" : \"test\"\n}\n```\n\n\n\u003efor now the web app and api run on different ports.\n\u003eapp : 5000 , api : 8000\n\n# Running for production\n\nThis section outlines how to setup and run shorty on web servers.\nIn this case I'll consider AWS EC2 instance.\n\n* Set up the EC2 instance.\n\n...[Learn more](http://bathompso.com/blog/Flask-AWS-Setup/)\n\n* Clone this git repository.\n\nChange the Host in `app.run()` to `0.0.0.0` , for both `shorty_api.py` and `app.py`\n\nNow if you run `python ./app.py` , shorty should run under the server IP as `\u003cserver host\u003e:\u003cport\u003e`\nBy default the `port` is `5000` , make sure to open the port before running the app.\n\n## Creating Script for running the app\n\nThe inbuilt flask server is not built for production , it might do down after a couple of days .\nSo we need to use production ready web servers , for this we'll use uWSGI and Nginx.\n\nFirst install uwsgi and nginx on EC2 instance\n\n`pip install uwsgi`\n\nIf it doesn't work install from distro repo\n\n**For Ubuntu**\n\n`sudo apt-get install uwsgi-core uwsgi-plugin-python \u0026 nginx`\n\n\n**For CentOS / Amazon Linux**\n\n`sudo yum install uwsgi \u0026 nginx`\n\n\n## Using uWSGI to run app.py and shorty_api.py\n\nThe uwsgi file is already setup in this repo , just change the \u003cuser\u003e to your user name .\nFor eg , \n\n\n`wsgi-file = /home/\u003cuser\u003e/shorty/app.py`\n\nJust change the `\u003cuser\u003e` to your sepecified user name , for me it would be\n\n`wsgi-file = /home/padam/shorty/app.py`\n\nSo update the `uwsgi_app` and `uwsgi_api` files.\n\nNow to run the script , run \n\n`uwsgi --ini uwsgi_app \u0026`\n\nThe `\u0026` is used to run app.py in background.\n\nFor the API run\n\n`uwsgi --ini uwsgi_api \u0026`\n\nBoth the processes will run in background .\n\n\n## Projects Used\n* [Skeleton CSS Framework](http://getskeleton.com)\n* [Clipboard.js](https://clipboardjs.com)\n\n## License\nThis project is licensed under the MIT Licene.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhighoncarbs%2Fshorty","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhighoncarbs%2Fshorty","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhighoncarbs%2Fshorty/lists"}