RESTBase/インストール

From mediawiki.org
This page is a translated version of the page RESTBase/Installation and the translation is 36% complete.

RESTbase ソースのダウンロード

この操作は、自分が権限を持っているあらゆるフォルダーで実施できます。

Git からダウンロードします:

git clone https://github.com/wikimedia/restbase.git

または、プロジェクトのリポジトリから ZIP ファイルをダウンロードして展開します。

Install node dependencies

RESTBase has been tested with node.js version 10.

restbase プロジェクトのディレクトリから、npm (nodejs の一部) を使用して Node の依存関係をインストールします。

npm install
また、npm install restbase を使用することもできますが、この場合は、サーバーを起動する前に環境変数 APP_BASE_PATHインストレーションフォルダー/node_modules/restbase を設定し、後述する server.js をはじめとする微妙に異なるファイル位置に注意してください。

設定

サンプル設定をコピーします:

cp config.example.yaml config.yaml

config.yaml ファイルの以下の部分を編集します:

 x-sub-request-filters:
   allow:
     - pattern: http://localhost/w/api.php
       forward_headers: true
     - pattern: http://localhost:8142
       forward_headers: true
     - pattern: /^https?:\/\//
  • 非公開ウィキを運営していない限り、この節を変更したり気にしたりする必要はありません (質問を参照)。
 paths:
   /{domain:ウィキのウェブサイト}:
  • ウィキのウェブサイト はあなたのウィキのベース ドメインです (同じドメインの異なるパスに複数のウィキがある場合は識別子)。 例えば、MediaWiki のベース URL は www.mediawiki.org です。 これは、同じサーバーを複数のウィキで使用する場合に、識別子のパスとして使用されます。 MediaWiki 1.35 以降の Parsoid で使用するためには、ドメインはウィキの $wgServer 構成のホスト部分と正確に一致しなければなりません。
   action:
     # XXX Check API URL!
     apiUriTemplate: http://ウィキのAPIエンドポイント
     baseUriTemplate: "{{'http://127.0.0.1:7231/{domain}/v1'}}"
  • ウィキのエンドポイント は、あなたのウィキの api.php の位置です。 例えば、MediaWiki の API エンドポイントは mediawiki.org/w/api.php です。 エンドポイント を参照してください
  • インターネットからアクセスできるため、baseUriTemplate がエンドポイントです。 apache/nginx からこのサービスに直接トラフィックをプロキシする場合は、"{{'http://{domain}/api/rest_v1'}}" のような URL を使用できます。 非標準のポートにアクセスできない人の問題を避けるために、これを推奨します。
   /parsoid:
     x-modules:
       - path: sys/parsoid.js
         options:
           # XXX Check Parsoid URL! .../rest.php is the default configuration
           # Parsoid/JS used http://localhost:8142
           parsoidHost: http://ウィキのRESTエンドポイント
  • MediaWiki 1.35 以降では、ウィキのRESTエンドポイント は、あなたのウィキの rest.php の場所です。 例えば、MediaWiki の REST エンドポイントは mediawiki.org/w/rest.php です。 REST API を参照してください。
  • MediaWiki 1.34 以前では、Parsoid/JS を使用すると、parsoidHost: のエントリが Parsoid サーバーの URL とポートに対応する必要があります。 Parsoid サーバーと RESTBase サーバーが同じマシン上にある場合は、localhost が有効な URL となりますが、通常は適切なポート番号を追加する必要があります。 Parsoid/JS は http://localhost:8142 を既定で使用していました。
   table:
     storage_groups:
       - name: default
         domains: /./
     backend: sqlite
     dbname: db.sqlite3
  • dbname: RESTBase は既定で、キャッシュ データの保存に sqlite データベースを使用します。 The file in the example script is named db.sqlite3 and is located in the same directory of the RESTBase folder. If you later want to run RESTBase as a service, you'll want to put the database on a different folder where the user running the service would have write permissions. For this you can change the line to: dbname: /var/lib/restbase/db.sqlite3 (and ensuring the user account running the service has permissions to write on it). Please note: You must manually add storage_groups parameter since they introduced storage groups for SQLite (see T225579).
  • In MediaWiki 1.35 and later you need to call Parsoid via your LocalSettings.php file in case the VisualEditor is not installed for the wiki:
wfLoadExtension(
    'Parsoid',
    'vendor/wikimedia/parsoid/extension.json' // Add absolute path here in case of issues with your job queue
);

If you want to serve requests from multiple wikis on the same RESTBase server, you should copy and replicate the entire /{domain:YOUR_WIKI_WEBSITE}: section, changing configurations as needed.

Run the server and Test

To test that it runs, from the RESTBase folder run:

node server.js

For testing, while it's running, on another terminal execute:

curl http://YOUR_RESTBASE_SERVER:7231/YOUR_WIKI_WEBSITE/v1/page/html/Main_Page

If everything is configured appropriately, you should see the HTML content of the Main_Page.

In a browser you can also test by navigating to http://YOUR_RESTBASE_SERVER:7231/YOUR_WIKI_WEBSITE/v1/ and you should see a page titled Wikimedia REST API. On this page you can test all manner of RESTBase methods and variables.

For other testing refer to GitHub.

If Restbase Port is blocked

If you do not see the page (your browser says it can't connect), your restbase server port may be blocked. Do the following:

curl http://YOUR_RESTBASE_SERVER:7231/YOUR_WIKI_WEBSITE/v1/
  • If you get {"items":["page","transform"]}, your restbase server port is ok.
  • If you did not get {"items":["page","transform"]}, then do:
    curl http://localhost:7231/YOUR_WIKI_WEBSITE/v1/
    
    • If you get {"items":["page","transform"]} the restbase server is not bad, but you cannot access the port.

To bypass the block, you can set proxypass to your Apache httpd configuration. See the Proxy requests to RESTBase from your webserver section for instructions.

Starting RESTBase Server automatically

Create a new user for the RESTBase service (optional, but recommended to avoid running it as root) and create a home folder for that user:

sudo useradd --home=/var/lib/restbase -M --user-group --system --shell=/usr/sbin/nologin -c "RESTBase for MediaWiki" restbase
sudo mkdir -p /var/lib/restbase
sudo chown restbase:restbase /var/lib/restbase

For installing the RESTBase server as a service with systemd, run sudo systemctl edit --force --full restbase.service. It will open a text editor. Fill it with the following contents:

[Unit]
Description=Mediawiki RESTBase Service
Documentation=https://www.mediawiki.org/wiki/Special:MyLanguage/RESTBase
Wants=local-fs.target network.target
After=local-fs.target network.target

[Install]
WantedBy=multi-user.target

[Service]
Type=simple
User=restbase
Group=restbase
WorkingDirectory=/path_to_restbase-master
ExecStart=/usr/bin/node /path_to_restbase-master/server.js
KillMode=process
Restart=on-success
PrivateTmp=true
StandardOutput=syslog

Replace path_to_restbase-master with the path to your restbase project directory.

To automatically start the RESTBase server at system startup,

systemctl enable restbase.service

To control the RESTBase server,

sudo systemctl start|stop|restart|status restbase.service

Proxy requests to RESTBase from your webserver

RESTBase must be accessible from the visitors of your site for some functions to work properly. Having RESTBase on a non-standard http port is problematic for some users behind a corporate proxy or firewall. To solve this, and specially to serve requests to RESTBase through HTTPS, you should set up a reverse-proxy on your webserver that would route requests at a given path of your wiki to the RESTBase server.

Apache

If you use apache, you can make a restbase.conf file like this, and put on /etc/httpd/conf.d of YOUR_RESTBASE_SERVER.

# Restbase.conf : usually on /etc/httpd/conf.d/

<VirtualHost *:80>
          AllowEncodedSlashes NoDecode

          ProxyPreserveHost On
          ProxyPass /YOUR_WIKI_WEBSITE/ http://localhost:7231/YOUR_WIKI_WEBSITE/ nocanon
          ProxyPassReverse /YOUR_WIKI_WEBSITE/ http://localhost:7231/YOUR_WIKI_WEBSITE/
          # Alternate configuration like WMF to have URLS like //example.com/api/rest_v1/
          # ProxyPass /api/rest_v1/ http://localhost:7231/YOUR_WIKI_WEBSITE/v1/ nocanon
          # ProxyPassReverse /api/rest_v1/ http://localhost:7231/YOUR_WIKI_WEBSITE/v1/

          # MediaWiki is located here:
          DocumentRoot /var/www/html

</VirtualHost>

Nginx

On the general configuration:

upstream restbase {
	server localhost:7231;
	keepalive 32;
}

# Hack so nginx doesn't decode the / character in page titles, causing
# errors on pages with that title. https://stackoverflow.com/a/20514632
map $request_uri $restbasequery {
        default "xx";
        "~/YOUR_WIKI_WEBSITE/v1/(?<xrestbasequery>.*)$" "$xrestbasequery";
        # Alternate configuration like WMF to have URLS like //example.com/api/rest_v1/
        #"~/api/rest_v1/(?<xrestbasequery>.*)$" "$xrestbasequery";
}

Inside the server block:

location /YOUR_WIKI_WEBSITE/v1/ {
# Alternate configuration like WMF to have URLS like //example.com/api/rest_v1/
# location /api/rest_v1/ {

        proxy_pass http://restbase/YOUR_WIKI_WEBSITE/v1/$restbasequery;
}

Configuring config.yaml for WMF like URLS

If you don't want to get a fetch error when using WMF like URLS, you should add x-host-basePath to the spec module like so:

        paths:
          /{domain:YOUR_WIKI_WEBSITE}/{api:v1}:
            x-modules:
              - spec:
                  info:
                    version: 1.0.0
                    title: Wikimedia REST API
                    description: Welcome to your RESTBase API.
                  x-route-filters:
                    - path: ./lib/normalize_title_filter.js
                      options:
                        redirect_cache_control: 's-maxage=0, max-age=86400'
                  x-host-basePath: /api/rest_v1

Testing

You should restart httpd (by apachectl restart or some means). In a browser you can now navigate to:

http://YOUR_WIKI_WEBSITE/YOUR_WIKI_WEBSITE/v1/

(alternate url like WMF setup):

http://YOUR_WIKI_WEBSITE/api/rest_v1/

and you should see a page titled Wikimedia REST API. And in this setting, you should add below to LocalSettings.php for VisualEditor.

$wgVisualEditorRestbaseURL = "http://YOUR_WIKI_WEBSITE/YOUR_WIKI_WEBSITE/v1/page/html/";
$wgVisualEditorFullRestbaseURL = "http://YOUR_WIKI_WEBSITE/YOUR_WIKI_WEBSITE/";
# Alternate URL scheme
# $wgVisualEditorRestbaseURL = "http://YOUR_WIKI_WEBSITE/api/rest_v1/page/html/";
# $wgVisualEditorFullRestbaseURL = "http://YOUR_WIKI_WEBSITE/api/rest_";

関連項目