Skip to content

A node server that protects a page by only serving it to users who have an active Patreon pledge tier

Notifications You must be signed in to change notification settings

mekane/patreon-api-backend-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Patreon API Backend for Node

This project is a Node server that protects a page by only serving it to users who log into Patreon and have an active pledge tier of sufficient amount. It uses V2 of the Patreon API.

Setup

  • npm install
  • Create a config.json (you can copy config.json.template) and fill in your values:
    • client id and secret values from the client entry on the "Clients and API Keys" page.
    • minimumPledgeCents the number of cents that are required in a user's pledge tier to see the protected content.
    • hostname (e.g. "www.mydomain.com")
    • port you want to listen on which is almost definitely going to be 80
  • Run the server: node index.js

Raw request logs and some diagnostics are output to standard out. A daily-rotating log file will be written to logs/

Note that when the server starts up it logs the redirect URL included in the OAuth request. You can copy-paste that into your Patreon client config section where you registered your application.

Features

  • Uses Express and Mustache for a lightweight and common server setup.
  • Data Access, Data Persistence, and Access Policy are injected into the server so they can be easily tested and swapped out for new implementations.

Limitations

  • Currently only serves one protected route - "views/successPage.mustache". An enhancement would be to make the code that protects the current route into an Express middleware
  • Currently uses an in-memory data store so if the node process is restarted all sessions are lost and users will need to repeat the "connect to Patreon" OAuth process. Enhancement would be to use a simple flat-file database to save the session data.
  • Re-queries the user's Patreon pledge status every time they access the protected route. Need to cache this for a short but reasonable amount of time.
  • The word "calculator" is hard-coded in a few places, which is kinda silly. Could easily be parameterized.
  • The PatreonAPI Interface has some pending test cases to handle some error cases that are hopefully uncommon (but still need to be handled at some point).

About

A node server that protects a page by only serving it to users who have an active Patreon pledge tier

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published