Code Monkey home page Code Monkey logo

guest-comments-api's Introduction

web-comments

A simple Express API written in TypeScript for guest comments on my static site @ rusingh.com.

Idealogy

Comments should be a part of my static site repository and handled at the static site level. This is most performant and keeps data in one place. There is no API endpoint to fetch comments as the app does not store any data by itself, for example, in a database.

All operations (well, just the three) interact with my GitHub repository. Currently only GitHub is supported but I may be open to adding support for Gitea or Codeberg should I switch to such options in the future.

Environment

The following environment variables are necessary:

  • NODE_ENV (optional) - defaults to production
  • SENDGRID_API_KEY - SendGrid API key used for sending notification emails
  • GITHUB_PAT - GitHub personal access token

API Endpoints

v1

POST /api/v1/comment/new

Accepts URL encoded requests. Redirects to ${origin}/thank-you/ or ${origin}/error. If the origin is not available, it simply responds with a 200/500 HTTP response.

Form encoded data required
  • name

  • email

  • site

  • comment

  • age (honeypot)

  • fallback-referer: Some browsers do not add referer headers to form submission requests. We rely on this as a fallback. Requires JavaScript client-side.

    const target = document.querySelector(
      "form > input[name='fallback-referer']"
    );
    if (target) target.setAttribute("value", window.location.href);
    

GET /api/v1/comment/moderate

Accepts URL encoded requests. Responds with a plain-text message upon success.

Query parameters
  • comment_id
  • action: approve or delete

Related

You may also be interested in checking open-jamstack-comments, which runs serverless.

guest-comments-api's People

Contributors

dependabot[bot] avatar maybethisisru avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 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.