GithubHelp home page GithubHelp logo

isabella232 / count Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kikobeats/count

0.0 0.0 0.0 659 KB

counting things, as microservice

Home Page: https://nicedoc.io/kikobeats/count

License: MIT License

JavaScript 100.00%

count's Introduction

count

Last version Build Status Dependency status Dev Dependencies Status

A simple microservice for counting things.

It's inspired by antirez.com and rauchg.com.

Deploy with Vercel

Usage

You can count whatever you want.

Imagine you are visiting a blog post and you want to count views.

Just pass the blog post relative path for counting pageviews:

kikobeats.com/culture-shipping → count.now.sh/pageviews/culture-shipping?incr → HTTP 201 Created

The service will return you the current counter, and the first and last timestamp associated:

{
  "updatedAt": 1564327678670,
  "createdAt": 1564327676653,
  "count": 25
}

For counting thing, you need to perform a GET to count.now.sh/:collection/:id, being supported the following query string:

  • increment|incr: When it is present, it specifies how much increment the value.

It doesn't matter if your id contains final slash; it will be sanitized.

For printing the value in your website, a representative code for doing that could be:

<script>
  fetch('https://count.now.sh' + window.location.pathname + '?increment&collection=pageviews)
    .then(res => res.json())
    .then(({ pageviews }) => {
      document.querySelector('.pageviews-container').classList.remove('display-none')
      document.querySelector('.pageviews-count').textContent = pageviews
    })
</script>

Environment Variables

Database

The service is backed at Firebase. You need to create an account (it's free!) and copy some relevant values you can find in your Firebase accounts tab.

FIRESTORE_PROJECT_ID

Type: string

The project id to use.

FIRESTORE_PRIVATE_KEY

Type: string

Your private key associated with your Firebase account.

It should be encoded in base64.

FIRESTORE_CLIENT_EMAIL

Type: string

Your email associated with your Firebase account.

Security

The following environment variables are optional and they are used protecting abusive use of the service from external traffic.

API_KEY

Type: string

When you provide it, all request to need to be authenticated in order to increment counters.

The API key can be provided:

  • as x-api-key request header.
  • as key or apiKey as query parameter.

You can use randomkeygen.com for generating an unique API key.

DOMAINS

Type: string|string[]

The list of allowed domains that authorized to interact with the service.

Rate Limit

The following variables are optional and providing them enable a rate limit window associated per request IP address.

RATE_LIMIT_WINDOW

Type: number

It defines a rate limit window, where the value specified is the number of seconds before RATE_LIMIT_MAX points are reset.

The value should be expressed in milliseconds.

RATE_LIMIT_MAX

Type: number

It defines a rate limit window, where the value is the maximum number of points can be consumed over RATE_LIMIT_WINDOW.

License

count-microservice © Kiko Beats, released under the MIT License.
Authored and maintained by Kiko Beats with help from contributors.

kikobeats.com · GitHub Kiko Beats · Twitter @Kikobeats

count's People

Contributors

dependabot-preview[bot] avatar imgbotapp avatar kikobeats 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.