Simple Server that waits for POST requests to tweets content. Works nicely for static websites, in my case — a Jekyll website hosted on GitHub Pages.
- Create your APP and get your keys here
- Create a new Heroku App
- In your new Heroku App, go to settings and create new Config Vars called
CONSUMER_KEY
,CONSUMER_SECRET
,ACCESS_TOKEN
andACCESS_TOKEN_SECRET
and enter your corresponding keys in the value fields - Clone this repo
- Deploy your app via the Heroku CLI or hook up your GitHub repository via the Deploy tab in your Heroku App
- After you deploy your app, your app url should display 'Waiting for tweets'
- We need to send our form data to our Heroku App. Our form submit function should look something like this:
form.addEventListener("submit", function(e){
var data = form.serialize();
fetch('YOUR HEROKU APP URL HERE', {
method:'POST',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-type':'application/json'
},
body:JSON.stringify(data)
})
.then((res) => res.json())
.then((data) => {
console.log(data.success);
if( data.success === true ){
// Show success message
}
});
});
- If the tweet was created successfully we should receive a success message in the console and also see our new tweet in our profile!