3

I have a Gitbook repository and I would like to serve it through Heroku. How should I setup my application for this purpose? How to tell `Gitbook serve' command to listen to Heroku's port?

Thank you.

jchristin
  • 7,352
  • 2
  • 15
  • 18

2 Answers2

5

Do not run the gitbook-cli directly on Heroku, gitbbok will use a lot of memory and pass the 512MB limit for a free dyno. The best way is to first build your book to a static website and then serve the static content with either nodejs with express static or with sinatra.

Run the following inside your gitbook folder.

gitbook build

A new folder will be created, _book and all your html files will be here. You can now create a new app on Heroku and serve your static content.

After you do gitbook build, you can serve that directory with Express by creating an app.js file like this:

var express = require('express'); 
var app = express();
app.use(express.static(__dirname + '/_book'));

app.listen(process.env.PORT || 3000);

Dead-easy. For more information: Static files served by node.js on heroku - is it a good idea?

Community
  • 1
  • 1
Joseph
  • 5,793
  • 4
  • 34
  • 41
2

1- Add gitbook-cli to your project:

npm install --save gitbook-cli

2- Add a Procfile to your project:

web: ./node_modules/gitbook-cli/bin/gitbook.js serve --port $PORT
jchristin
  • 7,352
  • 2
  • 15
  • 18
  • This way will chew a lot of memory, your app will crash with the 512MB dyno. Check the logs on Heroku once your app is running, you will notice. – Joseph Feb 16 '16 at 11:21