Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App error - Official staticman api on Heroku. #332

Open
IgorKowalczyk opened this issue Feb 22, 2020 · 79 comments
Open

App error - Official staticman api on Heroku. #332

IgorKowalczyk opened this issue Feb 22, 2020 · 79 comments
Assignees
Labels
bug question Signifies that the issue is a question where the user is seeking support.

Comments

@IgorKowalczyk
Copy link

IgorKowalczyk commented Feb 22, 2020

When I try to send data to your API that works on Heroku, I get an "Application error" message just like in the picture.
unknown

You will restore an older version, or fix the hosting of your application on Heroku, because I think it's your fault, not my form.

@alexwaibel
Copy link
Collaborator

@IgorKowalczyk support has been dropped for the public instance. Please refer to the README for instructions on how to easily deploy your own instance to the free tier of heroku. Self hosting should provide you a much more reliable experience and the free tier of heroku is more than sufficient. I will be closing this issue but please feel free to post any further questions you may have here.

@IgorKowalczyk
Copy link
Author

I tried to put it on the Heroku, but unfortunately, no guidebook worked for me...

@alexwaibel
Copy link
Collaborator

I'm happy to assist you if you can tell me more about what went wrong when deploying your own to Heroku. Unfortunately it is not feasible for us to run a reliable public instance off of this community run project.

@IgorKowalczyk
Copy link
Author

Let me explain. I've been doing everything as it's been handed down here: https://vincenttam.gitlab.io/post/2018-09-16-staticman-powered-gitlab-pages/2/ and here: https://muffinman.io/running-staticman-on-heroku/ unfortunately I didn't get to the correction in the second article because I had problems in the first one.
The command heroku config:set RSA_PRIVATE_KEY="$(cat key.pem)" did not work. My program was showing only an error: Program: does not exist. This may be related to $ openssl genrsa -out key.pem or to the "Stage 2: project config" section. I don't know what could be an error - maybe I misread the manual (I use the translator).

Sorry about my English too. (Translator - not google of course 😄)

@alexwaibel
Copy link
Collaborator

alexwaibel commented Feb 22, 2020

I would recommend consulting the README of this repo which has some more updated instructions. There is a "Deploy to Heroku" button in the README which simplifies much of the steps indicated in those links you provided. The discussion at the end of this issue may provide some additional clarity.

@IgorKowalczyk
Copy link
Author

Thank you, but I have a problem with the configuration file...

From: config.sample.json

{
  "gitlabToken." "YOUR_GITLAB_TOKEN."
  "githubToken." "YOUR_GITHUB_TOKEN."
  "rsaPrivateKey." "-----BEGIN RSA PRIVATE KEY---YOUR_KEY---END RSA PRIVATE KEY--"
  "port." 80
}

With the RSA key copied straight from the Github, change the text "YOUR_KEY" or something else, and remove the gitlabToken line or leave it as it is? Because I haven't seen it anywhere.

@alexwaibel
Copy link
Collaborator

If you are hosting on GitHub pages, then use the "githubToken" key and remove the "gitlabToken" key. If you are hosting on GitLab pages, then use the "gitlabToken" key and remove the "githubToken" key.

The text for the "rsaPrivateKey" value should be changed to the text of your own private RSA key as a single-line string with \n newline characters.

@IgorKowalczyk
Copy link
Author

The text for the "rsaPrivateKey" value should be changed to the text of your own private RSA key as a single-line string with \n newline characters.

I don't understand it...

@alexwaibel
Copy link
Collaborator

alexwaibel commented Feb 22, 2020

Have you created a public/private RSA key pair? If not, follow the steps outlined here to create one. Once you have a key pair generated, it'll likely be stored in ~/.ssh/id_rsa. This is your private RSA key. You can print it to your console with cat ~/.ssh/id_rsa. This will show your private key in the form:

-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp
wmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5
1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh
3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2
pIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX
GukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il
AkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF
L0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k
X6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl
U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=
-----END RSA PRIVATE KEY-----

As you can see, here we have a multiline, key string. However, the configuration value must all be on one line. You must make this a single line string with explicit \n newline characters. You can convert this by hand, or with the following command: cat ~/.ssh/id_rsa | sed '$!s/$/\\n/' | tr -d '\n'.

The output, which you will paste into your config file, should appear something like:

-----BEGIN RSA PRIVATE KEY-----\nMIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp\nwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5\n1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh\n3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2\npIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX\nGukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il\nAkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF\nL0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k\nX6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl\nU9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ\n37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=\n-----END RSA PRIVATE KEY-----

EDIT: The above instructions are incorrect. Please see the proper way to generate a key further down this thread

@IgorKowalczyk
Copy link
Author

IgorKowalczyk commented Feb 23, 2020

When I type the command heroku config:set RSA_PRIVATE_KEY="$(cat ./key.pem)" (I generated the key earlier) I get a message 'C:\Program' is not recognized as an internal or external command, operable program or batch file.
I don't know why this is happening.

I use the guide: https://yasoob.me/posts/running_staticman_on_static_hugo_blog_with_nested_comments/# (Readme does not help me much)

@alexwaibel
Copy link
Collaborator

Try using the heroku web interface rather than the command line. See instructions at this link under the section "Managing config vars" and the subsection "Using the Heroku Dashboard".

@IgorKowalczyk
Copy link
Author

Thank you. I just don't know how to change files like Profile. If I can write in a few minutes

@alexwaibel
Copy link
Collaborator

I'm sorry, I don't know what you are referring to. I'm not aware of any Profile file, nor should you need to make any file changes to deploy a Heroku instance. All you should have to do is click the deploy button from the README and then configure your config vars as described above. After that, you will still have to configure your website to call your Heroku instance.

@IgorKowalczyk
Copy link
Author

IgorKowalczyk commented Feb 23, 2020

The Procfile should contain a line: web: npm start, Heroku probably does something with this file.

Now create another file with the name of Procfile in the root of this cloned repo and add this to it:
web: npm start

@alexwaibel
Copy link
Collaborator

alexwaibel commented Feb 23, 2020

You do not need that file. That guide you are following is outdated and the "Deploy to Heroku" button does much of that for you. Again, all you should need to do is click that deploy button from our README and then add your config variables.

@IgorKowalczyk
Copy link
Author

IgorKowalczyk commented Feb 23, 2020

I did as in the guide in readme - I entered the first command (on the Herok website) git clone git@github.com:IgorKowalczykBot/staticman.git (My fork for the repository - current) and the console shows such an error as in the picture.

img

EDIT:
If I copy the original repository (git clone git@github.com:eduardoboucas/staticman.git) the situation is the same.

@alexwaibel
Copy link
Collaborator

That section of the README is referring to running the server on your own infrastructure. Those steps are not necessary when using Heroku. Again, the only steps you need to follow to deploy to heroku are clicking the deploy button and entering your config variables.

@IgorKowalczyk
Copy link
Author

But I still don't know how to enter the configuration variables. Maybe it's a Heroku section, like in the picture.

img

@alexwaibel
Copy link
Collaborator

Once you have clicked the "Deploy to Heroku" button, you will be redirected to the Heroku page. Here you will give your instance a name and click deploy. Once this has finished, click the "Manage App" button at the bottom of the screen. At the top there will be a tab called "Settings" which you will click. On the settings page, click "Reveal Config Vars" and add the configuration values for your instance.

@IgorKowalczyk
Copy link
Author

IgorKowalczyk commented Feb 23, 2020

I did as you said. I added those values. I don't know if you need to add NODE_ENV yet. When I open my application it shows an error: https://api-igorkowalczyk.herokuapp.com/

img

@alexwaibel
Copy link
Collaborator

You can check your logs to try to see what exactly went wrong. I believe you must set a value for the port config value as well. I don't believe a NODE_ENV is necessary. Without access to the logs it is hard for me to tell exactly what is wrong with your setup.

@IgorKowalczyk
Copy link
Author

2020-02-23T19:20:25.598063+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=api-igorkowalczyk.herokuapp.com request_id=78c9703b-434e-4863-ba78-497480ee36f4 fwd="77.111.245.53" dyno= connect= service= status=503 bytes= protocol=https
2020-02-23T19:20:27.256751+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=api-igorkowalczyk.herokuapp.com request_id=4658d9b4-9ae2-4d65-b645-82c6267ecd59 fwd="77.111.245.53" dyno= connect= service= status=503 bytes= protocol=https
2020-02-23T19:22:33.542508+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=api-igorkowalczyk.herokuapp.com request_id=fbe1a40a-5f29-42aa-948f-01c645938cd9 fwd="65.24.251.107" dyno= connect= service= status=503 bytes= protocol=https
2020-02-23T19:22:33.743342+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=api-igorkowalczyk.herokuapp.com request_id=a564d5ec-1373-475d-9c25-bbd9614da488 fwd="65.24.251.107" dyno= connect= service= status=503 bytes= protocol=https
2020-02-23T19:22:53.201986+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=api-igorkowalczyk.herokuapp.com request_id=b5b345ba-dcd9-49aa-a082-3ce39431130f fwd="65.24.251.107" dyno= connect= service= status=503 bytes= protocol=https
2020-02-23T19:22:53.282046+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=api-igorkowalczyk.herokuapp.com request_id=f90c10c8-d5db-4c5e-b47a-6a790f1e6c7c fwd="65.24.251.107" dyno= connect= service= status=503 bytes= protocol=https
2020-02-23T19:22:58.118016+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=api-igorkowalczyk.herokuapp.com request_id=fb2ca08f-c24d-42fe-9f0b-514353a41333 fwd="65.24.251.107" dyno= connect= service= status=503 bytes= protocol=https
2020-02-23T19:22:58.236792+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=api-igorkowalczyk.herokuapp.com request_id=62319441-afb9-4750-8aee-0f2f488ed82c fwd="65.24.251.107" dyno= connect= service= status=503 bytes= protocol=https
2020-02-23T19:23:55.565173+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=api-igorkowalczyk.herokuapp.com request_id=c9abdf9a-1fa2-4394-87d4-e8916b330c38 fwd="65.24.251.107" dyno= connect= service= status=503 bytes= protocol=https
2020-02-23T19:23:55.711107+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=api-igorkowalczyk.herokuapp.com request_id=d1dabfe1-7f1d-44b6-9548-bd79d9561aa5 fwd="65.24.251.107" dyno= connect= service= status=503 bytes= protocol=https

The logs don't tell anything. I copied everything that showed up there.

@alexwaibel
Copy link
Collaborator

Hmm I went to try to deploy the entire thing myself and am encountering similar issues with the RSA key. I will reopen this issue and investigate when I have time.

@IgorKowalczyk
Copy link
Author

I tried the pull request version but it still doesn't work. Heroku shows only the logs as in the picture.

img

@alexwaibel
Copy link
Collaborator

@IgorKowalczyk apologies, I believe my previous instructions for generating an RSA key were incorrect. The RSA_PRIVATE_KEY value you provide to Heroku should not have any \n newline characters. The key should however still all be on one line.

To summarize:

  • Create RSA key with ssh-keygen -t rsa -b 4096 -C "staticman key" -f ~/.ssh/staticman_key
  • Convert the string to be on one line with cat ~/.ssh/staticman_key | tr -d '\n'

Your key as entered into Heroku should look something like this:

-----BEGIN RSA PRIVATE KEY-----MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUpwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ51s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2pIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQXGukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63ilAkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlFL0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5kX6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2eplU9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=-----END RSA PRIVATE KEY-----

@alexwaibel
Copy link
Collaborator

@basemwahba yes, although your application doesn't have to be public. It can be created for just your account when you fill out the form to create a new GitHub application.

@IgorKowalczyk
Copy link
Author

Yeah. The key needs spaces (new lines) I didn't have them. After generating the key with PuTTy and copying it with N++ and pasting it into RSA_PRIVATE_KEY the application worked: https://api-igorkowalczyk.herokuapp.com/.
Shows "Hello from Staticman version 3.0.0! But when I go to the site: https://api-igorkowalczyk.herokuapp.com/v2/entry/igorkowalczyk/blog/master shows: ``Cannot GET /v2/entry/igorkowalczyk/blog/master
I remember "Invite the bot", but when I go to the site: https://api-igorkowalczyk.herokuapp.com/v2/connect/igorkowalczyk/blog, I get a sign: Invitation not found but I already invited my bot as shown in the screenshot below

img

PS: I want to use v2 API, however, seems better to me and it works the same (I guess), no need to add (and create new) applications.

@alexwaibel
Copy link
Collaborator

@IgorKowalczyk in your connect call, the username should be that of your bot account not your main account. The connect endpoint is meant to make your bot account accept the collaborator invite.

@IgorKowalczyk
Copy link
Author

@alexwaibel
Copy link
Collaborator

alexwaibel commented Mar 7, 2020

@IgorKowalczyk I was wrong, it should be your normal account name and not the bot account.

The correct form is a GET request to

https://api-igorkowalczyk.herokuapp.com/v2/connect/igorkowalczyk/blog

You can try revoking and resending the invitation. Watch the Heroku logs too to see if anything errors are being thrown there. Worst case, you can log in to the bot account and manually accept the invite.

@IgorKowalczyk
Copy link
Author

IgorKowalczyk commented Mar 9, 2020

xhr.send(encodeURI(data)) I don't know why it sends requests to the site address and /null e.g. "https://igorkowalczyk.github.io/blog//internet/2020/01/22/null" and requests aren't sent, I don't know how to put it to send any to "https://api-igorkowalczyk.herokuapp.com/SEND COMMNETS"

Post when i try: https://igorkowalczyk.github.io/blog//internet/2020/01/22/Bezpieczeństwo-w-sieci-nasze-dane.html

@ElArkk
Copy link

ElArkk commented Mar 14, 2020

@alexwaibel first of all, thank you for all your support here. I am running my own staticman instance on heroku as well, and trying to get it to work with my github pages blog. I was previously trying to use v3 using a personal access token. Thanks to you i now finally know that this won't work. So now I'm trying to switch to the GitHub App way as you described above. I have a couple of questions regarding that:

  • In my GitHub app setup, what do I put as Homepage URL and Webhook URL (both mandatory)?

  • In my staticman repo, in config.production.json, what variables do I need to set? Just githubAppID and githubPrivateKey or also still the rsaPrivateKey? And is the following the correct way of getting the variables from my env:

{
  "githubAppID": process.env.GITHUB_APP_ID,
  "githubPrivateKey": JSON.stringify(process.env.GITHUB_PRIVATE_KEY),
  "port": 8080
}

Any help on this would be really appreciated.

@alexwaibel
Copy link
Collaborator

@IgorKowalczyk I'm not really sure what you're asking. That sounds like a problem with how you're submitting the comment form from your website.

@ElArkk Those URLs should be the URL of your staticman instance I believe. I don't think it really matters in this case though. As far as the config values, to run as a GitHub app you'll need rsaPrivateKey, githubAppID, and githubPrivateKey. Note these are two separate private keys.

@IgorKowalczyk
Copy link
Author

I'm asking because my script can't send a request to api (and from that I don't know if this API works) The script below:

const commentForm = document.querySelector('.commentform');
const commentFormInputs = document.querySelectorAll('.commentform-input');
const slugInput = document.querySelector('.commentform-input-slug');
const optionsSlugInput = document.querySelector('.commentform-input-optionsslug');
const nameInput = document.querySelector('.commentform-input-name');
const emailInput = document.querySelector('.commentform-input-email');
const messageInput = document.querySelector('.commentform-input-message');
const errorMessagesDiv = document.querySelector('.commentform-errormessages');
const sendFailedDiv = document.querySelector('.commentform-sendfailed');
const sendSucceededDiv = document.querySelector('.commentform-sendsucceeded');
const url = 'https://api-igorkowalczyk.herokuapp.com/v2/entry/igorkowalczyk/blog/master';
function post(url, data, callback, errorCallback) {
const xhr = new XMLHttpRequest();
xhr.open('POST', url);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function() {
if (xhr.status === 200) {
callback(xhr.responseText);
} else if (xhr.status !== 200) {
errorCallback(xhr.responseText);
}
};
xhr.send;
}
if (commentForm) {
commentForm.addEventListener('submit', (e) => {
e.preventDefault();
errorMessagesDiv.innerHTML = '';
sendFailedDiv.style.display = 'none';
sendSucceededDiv.style.display = 'none';
const slug = slugInput.value.trim();
const optionsSlug = optionsSlugInput.value.trim();
const name = nameInput.value.trim();
const email = emailInput.value.trim();
const message = messageInput.value.trim();
let error = false;
let fatalError = false;
const messages = [];
if (name.length < 2) {
error = true;
messages.push('<div class="commentform-errormessage">Proszę wpisać imię.</div>');
}
if (email.search(/^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/) === -1) {
error = true;
messages.push('<div class="commentform-errormessage">Proszę wpisać poprawny e-mail.</div>');
}
if (message.length < 2) {
error = true;
messages.push('<div class="commentform-errormessage">Proszę wpisać wiadomość.</div>');
}
if (fatalError) {
return false;
}
if (error) {
errorMessagesDiv.innerHTML = messages.join('');
return false;
}
const params = [];
for (let i = 0; i < commentFormInputs.length; i++) {
const input = commentFormInputs[i];
params.push(`${ input.name }=${ input.value }`);
}
post(
console.log("Hello world!"),
e.target.getAttribute('data-action'),
params.join('&'),
function(text){
commentForm.reset();
sendSucceededDiv.style.display = 'block';
},
function(text){
sendFailedDiv.style.display = 'block';
}
);
});
}

And HTML (Rendered, Unrendered) here:
https://pastebin.com/a4Q9zsDN

@alexwaibel
Copy link
Collaborator

alexwaibel commented Mar 17, 2020

@IgorKowalczyk you can try sending the request to the API directly with a REST client like Postman to see if the request is working as expected. From there try replicating that request in your front-end code. The postman request would look something like:

image

I'd first try to just use the bare HTML form for submissions and then once you've got that working you can start adding back in the javascript stuff.

@ElArkk
Copy link

ElArkk commented Mar 17, 2020

@alexwaibel thank you! I'm still somehow getting MISSING_CONFIG_BLOCK errors, which I think can get thrown because of multiple underlying reasons. However, I got v2 to work finally, so I'll stick to that for now :). Thank you again!

@IgorKowalczyk
Copy link
Author

@alexwaibel But I don't care if the API works anymore, the JS script sends out the requests badly, I don't know what to do... I reworked it a little bit to send requests from one API, but it still doesn't display any errors. Maybe it's the fault of this element:

post(
console.log("Hello world!"),
e.target.getAttribute('data-action'),
params.join('&'),
function(text){
commentForm.reset();
sendSucceededDiv.style.display = 'block';
},
function(text){
sendFailedDiv.style.display = 'block';
}
);
});
}

I added console.log there to check if the script works there.

@alexwaibel
Copy link
Collaborator

@IgorKowalczyk well, this repo is strictly for fixing issues found in the Staticman API. I'm sorry, but I don't have the time to go through your project (and everyone else's that posts here) and figure out what's wrong with your front-end code.

As I suggested previously, I'd recommend going to bare HTML submission first to get the bare minimum comment submission functionality working and then you can start adding back in the javascript features you'd like to use. Additionally, the JS fetch API makes dealing with requests easier than using XMLHttpRequests in my opinion. You might find this Stack Overflow post to be helpful.

@arthrfrts
Copy link

arthrfrts commented Mar 22, 2020

For /v3 with github, you must authenticate as a GitHub app.

  1. Go to your GitHub Settings then Developer settings on the account hosting your website.
  2. Select the 'GitHub Apps' tab and click 'New GitHub App'.\
  3. Name the app, give it a Homepage URL, and give it full Read & Write Pull request access
  4. In Heroku, use the GITHUB_APP_ID instead of GITHUB_TOKEN and paste in the App ID from GitHub.
  5. Click 'Generate a private key' at the bottom of the GitHub app page
  6. Convert that downloaded key to be all on one line and add it to the Heroku config vars as GITHUB_PRIVATE_KEY
  7. You also probably have to click the 'Install App' tab in GitHub and install the app to your account.

Going a bit off memory but that should work.

Hi @alexwaibel! I followed your instructions in this comment, but I'm getting a Request timeout. Here's the log trail:

2020-03-22T18:01:39.749062+00:00 app[web.1]: (node:24) UnhandledPromiseRejectionWarning: Error: error:0909006C:PEM routines:get_name:no start line
2020-03-22T18:01:39.749084+00:00 app[web.1]:     at Sign.sign (internal/crypto/sig.js:112:29)
2020-03-22T18:01:39.749084+00:00 app[web.1]:     at Object.sign (/app/node_modules/jwa/index.js:152:45)
2020-03-22T18:01:39.749085+00:00 app[web.1]:     at Object.jwsSign [as sign] (/app/node_modules/jws/lib/sign-stream.js:32:24)
2020-03-22T18:01:39.749085+00:00 app[web.1]:     at Object.module.exports [as sign] (/app/node_modules/jsonwebtoken/sign.js:204:16)
2020-03-22T18:01:39.749086+00:00 app[web.1]:     at getSignedJsonWebToken (/app/node_modules/@octokit/app/dist-node/index.js:31:30)
2020-03-22T18:01:39.749086+00:00 app[web.1]:     at GitHub._authenticate (/app/lib/GitHub.js:58:21)
2020-03-22T18:01:39.749086+00:00 app[web.1]:     at /app/lib/GitHub.js:31:32
2020-03-22T18:01:39.749088+00:00 app[web.1]:     at new GitHub (/app/lib/GitHub.js:46:7)
2020-03-22T18:01:39.749089+00:00 app[web.1]:     at Object.module.exports.create (/app/lib/GitServiceFactory.js:11:14)
2020-03-22T18:01:39.749089+00:00 app[web.1]:     at /app/lib/Staticman.js:32:35
2020-03-22T18:01:39.749089+00:00 app[web.1]:     at new Staticman (/app/lib/Staticman.js:46:7)
2020-03-22T18:01:39.749090+00:00 app[web.1]:     at module.exports (/app/controllers/process.js:126:27)
2020-03-22T18:01:39.749090+00:00 app[web.1]:     at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2020-03-22T18:01:39.749090+00:00 app[web.1]:     at next (/app/node_modules/express/lib/router/route.js:137:13)
2020-03-22T18:01:39.749091+00:00 app[web.1]:     at /app/server.js:169:14
2020-03-22T18:01:39.749091+00:00 app[web.1]:     at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2020-03-22T18:01:39.749091+00:00 app[web.1]:     at next (/app/node_modules/express/lib/router/route.js:137:13)
2020-03-22T18:01:39.749091+00:00 app[web.1]:     at /app/server.js:144:14
2020-03-22T18:01:39.749092+00:00 app[web.1]:     at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2020-03-22T18:01:39.749092+00:00 app[web.1]:     at next (/app/node_modules/express/lib/router/route.js:137:13)
2020-03-22T18:01:39.749092+00:00 app[web.1]:     at /app/server.js:129:14
2020-03-22T18:01:39.749093+00:00 app[web.1]:     at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2020-03-22T18:01:39.749171+00:00 app[web.1]: (node:24) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
2020-03-22T18:01:39.749239+00:00 app[web.1]: (node:24) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
2020-03-22T18:02:09.723405+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/v3/entry/github/esporo/esporo/master/comments" host=esporo-staticman.herokuapp.com request_id=ebdaa58b-cb1f-4ceb-9a5e-dfd5997bdc2e fwd="138.36.184.66" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=https

This only happens when trying to use the v3 endpoint, v2 works fine.

@alexwaibel
Copy link
Collaborator

@arthrfrts which endpoint specifically are you trying to use?

@arthrfrts
Copy link

@alexwaibel I'm trying to connect using /v3/connect/github/<username>/<repository>.

@HarishMunagapati
Copy link

I have the same issue. Does anyone have a fix for it?

@alexwaibel
Copy link
Collaborator

@arthrfrts @HarishMunagapati sorry I disappeared in the middle of assisting you with this. I've been quite busy lately and haven't had the necessary bandwidth to devote to this project. For now I'd recommend using v2 and authenticating using a token as that's the most stable and documented approach.

@HarishMunagapati
Copy link

Sure, I'll reconfigure with v2 and comeback. When I did it yesterday, it's not showing the comments below the page.
let me give a shot again.

@HarishMunagapati
Copy link

@alexwaibel @mmistakes Even v2 is not working now, can you please help me with documentation I'm using Minimal Mistakes, latest release v4.19.2

@alexwaibel
Copy link
Collaborator

@HarishMunagapati
Copy link

@alexwaibel I went trough them over multiple times from for last weekdays 😄

Here is things confusing me.
1 . "_config.yml" Staticman url entry
in "https://travisdowns.github.io/blog/2020/02/05/now-with-comments.html" its mentioned as

staticman_url: https://${bridge_app_name}.herokuapp.com/v2/entry/${github-username}/${blog-repo}/master/comments

and in "https://spinningnumbers.org/a/staticman-heroku.html" its mentioned as

staticmanUrl: https://spinningnumbers-staticmandev2.herokuapp.com/v2/entry/willymcallister/willymcallister.github.io/master/comments

either of them didn't who any logs in my Heroku app and I see the error
"Sorry, there was an error with your submission. Please make sure all required fields have been completed and try again."

But luckily today, this worked for me @mmistakes can update in the configuration document.
endpoint : "https://staticman-twn.herokuapp.com/v2/entry/"

Now I'm trying to figure out nested comments.

@typo3ua
Copy link

typo3ua commented Dec 30, 2020

I had the same error ... I made my rsa private key in one line, without space and br

@VincentTam
Copy link
Contributor

VincentTam commented Jan 30, 2021

If you are hosting on GitHub pages, then use the "githubToken" key and remove the "gitlabToken" key. If you are hosting on GitLab pages, then use the "gitlabToken" key and remove the "githubToken" key.

The text for the "rsaPrivateKey" value should be changed to the text of your own private RSA key as a single-line string with \n newline characters.

@alexwaibel I just saw your comment and I would like to clarify that it's OK to have both of the parameters. My GitHub and GitLab (demo) projects linked to @staticmanlab using the same Heroku app name provide a proof. However, I'm now reading about the recent developments so as to replace my old instance open to public with a personal one.

@Poilssurlesseins
Copy link

Poilssurlesseins commented Aug 14, 2022

Hello,

I’ve been trying to make staticman run on my github page for a couple hours.
I am not able to make it work despite reading this help page. Thus I have a few questions that could help me understand and I would be very happy to receive some clarification.

I hope it was clear enough, if not feel free to ask for more information.
Thanks very much for reading, hope to get some answers :)

First capture
Capture d’écran 2022-08-14 à 18 42 43

Second capture
Capture d’écran 2022-08-15 à 02 07 04

@VincentTam
Copy link
Contributor

@Poilssurlesseins

  1. Yes. See my MWE: https://git.io/smdemo for details.
  2. First prompt: No, It's possible to use the GitHub app verison. Second prompt: Yes, that simplifies the setup.
  3. You don't need v2/connect, since we're using v3. The v3/entry is for POSTing comments. You have to connect both the NodeJS app (hosted on a 3rd-party server) and the GitHub App. I've written a guide for this at
    https://github.com/pacollins/hugo-future-imperfect-slim/wiki/staticman.yml#setting-up-your-own-staticman-api-instance-on-heroku.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug question Signifies that the issue is a question where the user is seeking support.
Projects
None yet
Development

No branches or pull requests

10 participants