简体   繁体   English

如何在Heroku上提供Gitbook

[英]How to serve a Gitbook on Heroku

I have a Gitbook repository and I would like to serve it through Heroku . 我有一个Gitbook存储库,我想通过Heroku提供它。 How should I setup my application for this purpose? 我应该如何为此目的设置我的应用程序? How to tell `Gitbook serve' command to listen to Heroku's port? 如何告诉“Gitbook serve”命令听Heroku的端口?

Thank you. 谢谢。

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. 不要直接在Heroku上运行gitbook-cli ,gitbbok将使用大量内存并通过512MB限制免费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 . 最好的办法是,先构建你的书给一个静态的网站,然后服务于静态内容有任何明示与静态或与西纳特拉 的NodeJS。

Run the following inside your gitbook folder. gitbook文件夹中运行以下命令

gitbook build

A new folder will be created, _book and all your html files will be here. 将创建一个新文件夹, _book和所有html文件将在此处。 You can now create a new app on Heroku and serve your static content. 您现在可以在Heroku上创建一个新应用程序并提供静态内容。

After you do gitbook build , you can serve that directory with Express by creating an app.js file like this: 在进行gitbook build ,您可以通过创建app.js文件来使用Express服务该目录,如下所示:

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? 有关更多信息: 由heroku上的node.js提供的静态文件 - 这是一个好主意吗?

1- Add gitbook-cli to your project: 1-将gitbook-cli添加到您的项目中:

npm install --save gitbook-cli

2- Add a Procfile to your project: 2-将Procfile添加到项目中:

web: ./node_modules/gitbook-cli/bin/gitbook.js serve --port $PORT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM