GithubHelp home page GithubHelp logo

nigel5 / ocurl Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 1.29 MB

An API to shorten your URLs

Home Page: https://ocurl.io

License: MIT License

JavaScript 63.34% HTML 33.82% Shell 1.29% CSS 1.54%
api url utility service

ocurl's Introduction

One Click URL

Check it out at ocurl.io

OCUrl: URL shortening service API

Extensions: Discord Bot | Chrome Extension

Features

  • Public REST API for developers
  • Cached (still works if cache is offline!)
  • Unobtrusive one click Chrome extension to shorten current page URLs and copy to clipboad
  • Simple configuration and deployment. Docker ๐Ÿ‹ ready.
  • Easy configuration
  • Google Cloud Operations ready

System Diagram

Not mentioned is the backup database, and CDN for the homepage.

Middleware Diagram

Public API

There are only two types of responses: data (200) and error response (5xx).

A data response is the following structure

{
  "data": [Object]
}

An error response is the following structure

{
  "error": [Object],
  "message": string
}
Method Endpoint Query parameters? Description
GET /api/v1/url q {string} A valid destination url. l {number} Length of short url path Get a short url for destination q
GET /api/v1/decode q {string} The short url Get destination for short url or key q.
ANY /api/v1/health none Server health [ok 200,unavailable 500]

Example

fetch('https://onecurl.com/api/v1/url?q=https://github.com')
  .then((res) => res.json())
  .then((json) => console.log(json));

// Output:
// {
//   "data": {
//     "url": "localhost:3000/ou6p1"
//   }
// }

Requirements

  • Node.js v12.18.3 LTS
  • Redis 6
  • PostgreSQL

Docker Setup

The easiest way to setup the application is by using Docker.

To run in Docker,

docker-compose up --build

This will pull node:14, redis:latest, and postgres:latest.

Local Development Setup

First, start up Postgres, and optionally, Redis if you want a cache. Modify the dev configuration file with the hostname and ports if required. Then,

yarn install
yarn dev // Nodemon will watch for changes and automatically restart the server

Configuration

Global application settings are exported in main.js. Ocurl provides configuration files for development, producation, and docker by default. ocurl.conf.dev.json, ocurl.conf.docker.json, ocurl.conf.prod.json. The configuration files are loaded depending on the environmental variable.

Rate Limiter Setting

The rate limiter can be configured with maximum number of requests, and time in seconds till expiry.

Stackdriver Logging

To enable Google Cloud Platform Operations Logging (formerly known as Stackdriver), export the path to the credentials file.

EXPORT GOOGLE_APPLICATION_CREDENTIALS="thePath"

Or create a .env file in the root of this project with this variable.

License

MIT

ocurl's People

Contributors

dependabot-preview[bot] avatar nigel5 avatar

Watchers

 avatar

ocurl's Issues

Incorrect redirection for www destinations without protocol

Describe the bug
Incorrect redirection for www destinations without protocol

To Reproduce
Steps to reproduce the behavior:

  1. Create new short url for any www with no protocol (e.g. www.example.com)
  2. Visit provided link
  3. Observe redirected to ocurl.io. Expected www.example.com

Expected behavior
A clear and concise description of what you expected to happen.
Expected www.example.com

Screenshots
N/A

Desktop (please complete the following information):
N/A

Smartphone (please complete the following information):
N/A

Additional context
N/A

Rate Limit

Is your feature request related to a problem? Please describe.
Limit the API usage for users. This will save costs and discourage misuse of the service.

Describe the solution you'd like
Rate limit for public facing API

Describe alternatives you've considered
N/A

Additional context
N/A

bug: Not working for URLs with spaces in query parameter values

Expected destination: https://duckduckgo.com/?q=google+cloud+big+query&t=osx&ia=web

Actual destination: https://duckduckgo.com/?q=google

Log entry:

{
  "insertId": ".........5SUU3kZS.l7L8qK4QvcU2LG",
  "jsonPayload": {
    "metadata": {},
    "message": "/api/v1/url?q=https://duckduckgo.com/?q%3Dgoogle"
  },
  "httpRequest": {
    "requestMethod": "GET",
    "requestUrl": "/api/v1/url?q=https://duckduckgo.com/?q%3Dgoogle",
    "status": 200,
    "responseSize": "41",
    "userAgent": "Python/3.5 aiohttp/3.6.2",
    "latency": "0.020s"
  },
  "resource": {
    "type": "global",
    "labels": {
      "project_id": "ocurl-287802"
    }
  },
  "timestamp": "2020-10-04T20:15:14.227999925Z",
  "severity": "INFO",
  "logName": "projects/ocurl-287802/logs/winston_log_reqlog",
  "trace": "projects/ocurl-287802/traces/27bcf49d49df4a56a72fe87fad59d675",
  "receiveTimestamp": "2020-10-04T20:15:14.401084342Z"
}

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.