Skip to content

A free serverless URL shortener service built with Google Apps Script and stored in Google Sheets.

License

Notifications You must be signed in to change notification settings

canaria3406/canaria-url

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


canaria-url

A free serverless URL shortener service built with Google Apps Script and stored in Google Sheets.
Live Demo : url.canaria.cc

Read Script Details

When you visit a URL (EX: url.canaria.cc/example), it will redirect you to 404.html.
The JavaScript code within 404.html will send the parameter example to Google Apps Script.
Google Apps Script will then compare the data in Google Sheets, and if there is a match, it will return the long URL; otherwise, it will return url.canaria.cc.
The 404.html will then redirect the webpage to the returned URL.

  var dbrow = 1;
  var url = "https://url.canaria.cc/";
  var sheet = SpreadsheetApp.getActive();
  var db = sheet.getSheetByName('database');

  while (db.getRange(dbrow, 1).getValue() != '') {
    if (db.getRange(dbrow, 2).getValue() == hashnum) {
      url = db.getRange(dbrow, 3).getValue();
      break;
    }
    dbrow++;
  }

  return url;

Write Script Details

Check if the short URL is empty, duplicated, or compliant.
If any issues are found, fix them, and then write the URL in Google Sheets.
Write the current time, short URL, and long URL to Google Sheets, and return the complete short URL.

  var sheet = SpreadsheetApp.getActive();
  var db = sheet.getSheetByName('database');

  // Checking URL here

  db.appendRow([Date(), num, targeturl]);
  url2 = "https://url.canaria.cc/" + num;
  
  return url2;

About

A free serverless URL shortener service built with Google Apps Script and stored in Google Sheets.

Topics

Resources

License

Stars

Watchers

Forks