Coder Social home page Coder Social logo

simonaco / serverless-url-shortener Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jeremylikness/serverless-url-shortener

0.0 3.0 0.0 505 KB

Azure Function for a URL shortening website. Uses serverless functions, Azure Table Storage and Application Insights.

License: MIT License

C# 63.16% HTML 22.53% JavaScript 14.31%

serverless-url-shortener's Introduction

Azure Functions App for URL Shortening

This project represents a fully serverless implementation for a URL shortening utility implemented with Azure Functions and Azure Table Storage. The project as deployed will enable you to create short URLs and provides an endpoint for redirecting the short URL to the target URL. It uses proxies to allow redirection from the root of the domain.

Deploy to Azure

This project leverages Azure Resource Management Templates to make it easy to provision with a single click.

NOTE: this represents an early version of development. The latest source code is available in the jlik.me repository.

Getting Started

This section is walkthrough to deploy and test the application. Click on the link below to watch a video that demonstrates the following steps.

Video Walk-through

For a comprehensive explanation of the source code and how the application was built, read: Build a Serverless Link Shortener with Analytics Faster than Finishing Your Latte.

Simply click on the deploy button to get started. The first dialog prompts for information needed to generate the resources.

Initial Form for Deploying to Azure

If you have multiple directories and subscriptions, choose the correct one. Pick a resource group and give your app a name. The fallback URL is the URL the service will redirect to when an invalid short URL is provided. The "UTM Source" is used for tagging social media campaigns. Both values will be updated to the application settings for the function app and may be changed at a later date. Choose the storage option (the default should be fine). Keep the default URL for the repository unless you forked the code for your own.

Note: sometimes the deployment may fail with a random error. If it does this, choose the option to try again. In my experience it will often succeed on the second try, especially if the error is related to source code (there appear to be some sporadic issues with fetching the code from GitHub).

This is what a successful screen looks like:

List of Deployment Steps

Once the project has deployed, click or tap "Manage" to navigate to the resource group in the Azure portal. Click on the function app name.

Resource List

Next, tap on the UrlIngest function to create your first short URL. Tab the "Test" tab on the right to enter a request body and specify the following:

{
    input: "https://blog.jeremylikness.com/"
}

(You can choose your own URL).

Select UrlIngest Function

Tap the "Run" button and you should receive a list of results with your shortened URL.

Short URL Response

You can either copy the "ShortUrl" property from the JSON returned, or build the link yourself from the short url. Open a browser, and paste the URL. This example assumes the app name "jrlshorturl" was used.

http://jrlshorturl-function.azurewebsites.net/2q

The site should redirect to the URL you set up in the previous step. Your URL is ready to go! To view analytics, tap on the Function App name then click the Application Insights feature.

Selecting Application Insights

You should immediately begin to see data generated from your functions app.

Client Web Tool

For your convenience, you can also create a lightweight Docker image to run a small client to make it easier to generate URLs without logging into the portal. First, navigate to the "UrlIngest" function and click "Get function URL."

Get the Function URL

Copy the value. This should include your secret function key. Next, navigate to the webApp directory and replace the value for apiRoot in first line of index.js with the URL you just copied.

const apiRoot = "https://<hostname>.azurewebsites.net/api/UrlIngest?code=<funcAppKey>";

Save the file and build the Docker image:

docker build -t shortener .

Once the image has built, run it. This example maps it from the default web port 80 to 8888.

docker run -d -p 8888:80 shortener

Navigate to http://localhost:8888 to run the app.

Shortener App

Important note about CORS: in order for the function URL to be accessible from your local browser, it must be configured with a Cross-Origin Rresource Sharing (CORS) entry in the function app. Learn how to with this link: How to manage a function app in the Azure portal.

Choose whether or not to add the configured source and redirect to the various mediums, then paste the long URL and tap "Shorten" to generate the short URLs.

Follw me on Twitter: @JeremyLikness

serverless-url-shortener's People

Contributors

jeremylikness avatar

Watchers

James Cloos avatar Simona Cotin avatar  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.