Giter Site home page Giter Site logo

healeycodes / gatsby-serverless-comments Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 1.0 438 KB

๐Ÿ”ง Use Netlify serverless functions to add commenting to a static website

Home Page: https://healeycodes.com/adding-comments-to-gatsby-with-netlify-and-github/

License: MIT License

JavaScript 100.00%
gatsby netlify serverless blog comments netlify-serverless-functions

gatsby-serverless-comments's Introduction

gatsby-serverless-comments

My blog post: Adding Comments to Gatsby with Netlify Serverless Functions + GitHub


Use Netlify serverless functions to let users add comments to a static website.

  1. ๐Ÿ‘ฉ User enters a comment and clicks submit.
  2. โš™๏ธ A serverless function receives the data and hits GitHub's API.
  3. ๐Ÿ”ง It reads the existing comments.json , appends the new comment, and saves.
  4. ๐Ÿšง A new commit triggers a Netlify build.
  5. โœ… The new version of the website is deployed!

The new comment is visible ~30 seconds โฐ after the first click.


See /src/pages/index.js for the user visible page.

See /functions/comment.js for the serverless function.

Why?

  • Accept user comments and store them on GitHub. No database required.

  • Avoid using third-party plugin solutions that leak your user's data.


Setup

Set the following environmental variables on Netlify:

  • GITHUB_PAT_TOKEN to your GitHub personal access token.
  • GITHUB_REPO to the repository where this code is located.
  • GITHUB_USER your GitHub username.

Set up the site on Netlify to continuously deploy on commits (this the default).

Visit the deploy preview, or production version, and submit a comment from the root path (/). There is a example form that submits a PUT request.

You should see a 204 response in the browser console. Else, check the Netlify functions logs for errors.

gatsby-serverless-comments's People

Contributors

healeycodes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

chenyfan-tester

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.