Staticman: Heroku Application Error

Created on 23 Jan 2021  路  5Comments  路  Source: eduardoboucas/staticman

After clicking the button in README.md I enter a name and click "Create App". After a minute or two, I get the message "Your app was successfully deployed." However, if I click the button "View" another page opens with the following error message:

 Application error

An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command
heroku logs --tail 

I found the following issues #394 & #364 (the last one is similar however, I have not even entered my credentials yet)... I tried using Safari as well as Firefox and Firefox Developer Edition (in case my browsers were stripping the referee headers) and this link from #394:
https://heroku.com/deploy?template=https://github.com/eduardoboucas/staticman/tree/master
and I am still getting the Application Error.

All 5 comments

When I run the command heroku logs --tail I get the following:

2021-01-23T16:27:38.578873+00:00 app[api]: Initial release by user <my email address>
2021-01-23T16:27:38.578873+00:00 app[api]: Release v1 created by user <my email address>
2021-01-23T16:27:38.693018+00:00 app[api]: Release v2 created by user <my email address>
2021-01-23T16:27:38.693018+00:00 app[api]: Enable Logplex by user <my email address>
2021-01-23T16:27:39.000000+00:00 app[api]: Build started by user <my email address>
2021-01-23T16:28:38.261575+00:00 app[api]: Deploy by user <my email address>
2021-01-23T16:28:38.261575+00:00 app[api]: Release v3 created by user <my email address>
2021-01-23T16:28:38.281753+00:00 app[api]: Scaled to web@1:Free by user <my email address>
2021-01-23T16:28:42.000000+00:00 app[api]: Build succeeded
2021-01-23T16:28:42.306729+00:00 heroku[web.1]: Starting process with command `npm start`
2021-01-23T16:28:44.493617+00:00 app[web.1]:
2021-01-23T16:28:44.493632+00:00 app[web.1]: > [email protected] prestart
2021-01-23T16:28:44.493633+00:00 app[web.1]: > if [ ! -d node_modules ]; then npm install; fi
2021-01-23T16:28:44.493633+00:00 app[web.1]:
2021-01-23T16:28:44.501013+00:00 app[web.1]:
2021-01-23T16:28:44.501014+00:00 app[web.1]: > [email protected] start
2021-01-23T16:28:44.501014+00:00 app[web.1]: > node index.js
2021-01-23T16:28:44.501014+00:00 app[web.1]:
2021-01-23T16:28:44.849819+00:00 app[web.1]: Error: Empty key given
2021-01-23T16:28:44.849855+00:00 app[web.1]: at NodeRSA.module.exports.NodeRSA.importKey (/app/node_modules/node-rsa/src/NodeRSA.js:178:19)
2021-01-23T16:28:44.849855+00:00 app[web.1]: at Object.<anonymous> (/app/lib/RSA.js:6:5)
2021-01-23T16:28:44.849856+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1108:14)
2021-01-23T16:28:44.849856+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
2021-01-23T16:28:44.849856+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:973:32)
2021-01-23T16:28:44.849857+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:813:14)
2021-01-23T16:28:44.849857+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:997:19)
2021-01-23T16:28:44.849857+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:92:18)
2021-01-23T16:28:44.849857+00:00 app[web.1]: at Object.<anonymous> (/app/controllers/encrypt.js:4:13)
2021-01-23T16:28:44.849857+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1108:14)
2021-01-23T16:28:44.903653+00:00 heroku[web.1]: Process exited with status 0
2021-01-23T16:28:44.944658+00:00 heroku[web.1]: State changed from starting to crashed
2021-01-23T16:28:44.947909+00:00 heroku[web.1]: State changed from crashed to starting
2021-01-23T16:28:49.753525+00:00 heroku[web.1]: Starting process with command `npm start`
2021-01-23T16:28:53.301422+00:00 app[web.1]:
2021-01-23T16:28:53.301436+00:00 app[web.1]: > [email protected] prestart
2021-01-23T16:28:53.301437+00:00 app[web.1]: > if [ ! -d node_modules ]; then npm install; fi
2021-01-23T16:28:53.301437+00:00 app[web.1]:
2021-01-23T16:28:53.322432+00:00 app[web.1]:
2021-01-23T16:28:53.322434+00:00 app[web.1]: > [email protected] start
2021-01-23T16:28:53.322434+00:00 app[web.1]: > node index.js
2021-01-23T16:28:53.322435+00:00 app[web.1]:
2021-01-23T16:28:53.874567+00:00 app[web.1]: Error: Empty key given
2021-01-23T16:28:53.874597+00:00 app[web.1]: at NodeRSA.module.exports.NodeRSA.importKey (/app/node_modules/node-rsa/src/NodeRSA.js:178:19)
2021-01-23T16:28:53.874599+00:00 app[web.1]: at Object.<anonymous> (/app/lib/RSA.js:6:5)
2021-01-23T16:28:53.874600+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1108:14)
2021-01-23T16:28:53.874601+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
2021-01-23T16:28:53.874602+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:973:32)
2021-01-23T16:28:53.874602+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:813:14)
2021-01-23T16:28:53.874602+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:997:19)
2021-01-23T16:28:53.874602+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:92:18)
2021-01-23T16:28:53.874603+00:00 app[web.1]: at Object.<anonymous> (/app/controllers/encrypt.js:4:13)
2021-01-23T16:28:53.874603+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1108:14)
2021-01-23T16:28:53.977894+00:00 heroku[web.1]: Process exited with status 0
2021-01-23T16:28:54.030222+00:00 heroku[web.1]: State changed from starting to crashed
2021-01-23T16:29:47.637614+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=<heroku app name> request_id=196b4314-8b0a-476f-8fdf-4df303d21daa fwd="68.6.219.60" dyno= connect= service= status=503 bytes= protocol=https
2021-01-23T16:30:54.644374+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=<heroku app name> request_id=2823928b-5051-4c7b-bc99-bcdf3c28f085 fwd="68.6.219.60" dyno= connect= service= status=503 bytes= protocol=https
2021-01-23T16:31:04.420138+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=<heroku app name> request_id=4609c891-eb9e-4a6d-b220-acc9158037e4 fwd="68.6.219.60" dyno= connect= service= status=503 bytes= protocol=https

Hi!

[EDITED : @Isaac-Tait ]

[first time I help somebody in github]
Go other way! (I'm on ubuntu) (I just add staticman a few days ago) :

Delete your heroku app.
Make githubBOTaccount (verified).
Install heroku CLI on your OS.
Generate new personnal access token with githubBOT (save it in txt file) + select scopes (repo -all + user -all)

Then :
git clone https://github.com/eduardoboucas/staticman.git

Go in staticman folder.
Create "Procfile" file add "npm start".
openssl genrsa -out key.pem
Create "config.production.json" add this :

{
  "githubToken": "yourtoken",
  "rsaPrivateKey": "the entier (RSA private) key",
  "port": 8080
}

heroku login
heroku create nameofyourapp

heroku config:set NODE_ENV="production"
heroku config:set GITHUB_TOKEN="votretoken"
heroku config:set RSA_PRIVATE_KEY="$(cat ./key.pem)"

git checkout -b production 55d1430

Then :
in .gitignore add "!config.production.json"

Deploy :

git add .
git commit -m "Set up Staticman v3 for deployment to Heroku"
git push heroku production:master

go see your app if everything good you will see :
Hello from Staticman version 3.0.0!

After install just do configuration and your partials.

[EDITED: Thanks! @VincentTam ]

@subversive-eu Hi thanks for your help! I would like to point out that la cl茅 entier in your config.production.json can be translated to the entier (RSA private) key.

For a minimal Heroku config, no installation is needed, as suggested by the README file. Just click the Heroku deploy button and fill in the necessary API config parameters in the apps setting page.

P.S. The noun 芦 cl茅 :key: 禄 in French :fr: is feminine :female_sign:, so the adjective 芦 entier 禄 that follows should be written as 芦 enti猫re 禄, so that it agrees with the gender of the preceding noun 芦 cl茅 :key: 禄.

@Isaac-Tait These two lines in the log explain everything.

Error: Empty key given
at NodeRSA.module.exports.NodeRSA.importKey (/app/node_modules/node-rsa/src/NodeRSA.js:178:19)

You need to set generate your own RSA private key PEM file and paste the content of this file into your Heroku app's config variable.

staticman-rsa

Successful example: https://github.com/VincentTam/TestStaticmanLab/pull/95

Screenshot from 2021-02-01 11-36-53
Screenshot from 2021-02-01 11-32-49

Reference: https://hajekj.net/2020/04/15/staticman-setup-in-app-service/

Remarks about the referenced article:

I tried following the instructions about the additional manual treatment of the RSA PEM file (the removal of the first and the last \n) without success. As last, I decided not to follow its advice and I just pasted the contents of the PEM file into the text area as shown in the above screenshot. Do this for both RSA_PRIVATE_KEY and GITHUB_PRIVATE_KEY. Finally, I've managed to get through this problem.

Screenshot from 2021-02-01 11-50-23
Screenshot of my private app: heroku log -a secretman3 --tail

In the middle of this screenshot, you see that there's an InvalidAsn1Error, which is caused by the incorrect formatting of the Heroku app's config variable RSA_PRIVATE_KEY. After I corrected that (observe the green line set ... by user ...), the error was gone, and I was able to access the v3/encrypt endpoint.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mmistakes picture mmistakes  路  8Comments

ex-punctis picture ex-punctis  路  8Comments

taxilly picture taxilly  路  15Comments

donaldboulton picture donaldboulton  路  9Comments

zburgermeiszter picture zburgermeiszter  路  8Comments