Skip to content

Instantly share code, notes, and snippets.

@jannispaul
Last active February 23, 2022 18:00
Show Gist options
  • Save jannispaul/3787603317fc9bbb96e99c51fe169731 to your computer and use it in GitHub Desktop.
Save jannispaul/3787603317fc9bbb96e99c51fe169731 to your computer and use it in GitHub Desktop.
My modified tutorial for Staticman on Heroku

Selfhosted staticman instance on Heroku

Setup is based on these tutorials

https://www.datascienceblog.net/post/other/staticman_comments/

https://vincenttam.gitlab.io/post/2018-09-16-staticman-powered-gitlab-pages/2/

https://yasoob.me/posts/running_staticman_on_static_hugo_blog_with_nested_comments/

Setup

  1. Create a new GitHub account for the Staticman API

  2. Create a GitHub token with repo acccess (check the repo checkbox) for the new account: https://github.com/settings/tokens,

  3. Clone an instance of Staticman: git clone https://github.com/eduardoboucas/staticman/

  4. Move into the staticman folder: cd ~/staticman

  5. In the staticman folder, create a file called Procfile and store a single line in there: web: npm start

  6. Create a private RSA key for use with the API: openssl genrsa -out key.pem

  7. Create a Heroku account

  8. Log into the Heroku CLI using heroku login,

  9. Create a new Staticman app and configure it:

     heroku create {nameOfYourStaticmanApp}`
     heroku config:set NODE_ENV="production" 
     heroku config:set RSA_PRIVATE_KEY="$(cat key.pem)" 
     heroku config:set GITHUB_TOKEN="Your_Token"
    
  10. Create a production branch: git checkout -b production origin/dev

  11. Add !config.production.json to .gitignore

  12. Commit the changes:

    git add config.production.json Procfile .gitignore 
    git commit -m "Set up Staticman v3 for deployment to Heroku"
    
  13. Deploy the API: git push heroku production:master

  14. After the API has been built successfully, you should be greeted with Hello from Staticman version 3.0.0! when visiting your API instance at https://{nameOfYourStaticmanApp}.herokuapp.com.

Fixing it

On POST using the API endpoint https://{nameOfYourStaticmanApp}.herokuapp.com/v3/entry/github/{githubUsername}/{repositoryName}/{branchName}/{folderLikeCommentsOrReviews} the instance should show an error: "Internal Server Error"

To fix it use this pull request eduardoboucas/staticman#288

git pull origin pull/288/head
git push heroku

In case that pull request doesnt work check out these

eduardoboucas/staticman#299 (comment)

@VincentTam
Copy link

It's better to select a minimal set of priviledges for the GitHub token.

Screenshot_2019-09-12 Build software better, together

@jannispaul
Copy link
Author

Thanks, I changed the wording. With "full repo access" I meant all the checkboxes listed under repo. Those are active in your tokens too, right?

@VincentTam
Copy link

Thanks for clarification. Yeah, for sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment