Jakarta Servlet 5.0 をとりあえず動かす

f:id:bau1537:20210925143925j:plain

Jakarta Servlet 5.0

Maven プロジェクトの作成

$ mkdir demo-jakarta-servlet-5
$ cd demo-jakarta-servlet-5/
$ mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes \
> -DarchetypeArtifactId=maven-archetype-webapp
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] >>> maven-archetype-plugin:3.2.0:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO] 
[INFO] <<< maven-archetype-plugin:3.2.0:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO] 
[INFO] 
[INFO] --- maven-archetype-plugin:3.2.0:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] Archetype [org.apache.maven.archetypes:maven-archetype-webapp:1.4] found in catalog remote
Define value for property 'groupId': org.example
Define value for property 'artifactId': servlet
Define value for property 'version' 1.0-SNAPSHOT: : 
Define value for property 'package' org.example: : 
Confirm properties configuration:
groupId: org.example
artifactId: servlet
version: 1.0-SNAPSHOT
package: org.example
 Y: : Y
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: maven-archetype-webapp:1.4
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: org.example
[INFO] Parameter: artifactId, Value: servlet
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: org.example
[INFO] Parameter: packageInPathFormat, Value: org/example
[INFO] Parameter: package, Value: org.example
[INFO] Parameter: groupId, Value: org.example
[INFO] Parameter: artifactId, Value: servlet
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Project created from Archetype in dir: /home/bookstore/IdeaProjects/demo-jakarta-servlet-5/servlet
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  19.312 s
[INFO] Finished at: 2021-09-23T15:49:15+09:00
[INFO] ------------------------------------------------------------------------
  • プロジェクトの構成はこう
$ cd servlet/
$ tree .
.
├── pom.xml
└── src
    └── main
        └── webapp
            ├── WEB-INF
            │   └── web.xml
            └── index.jsp

4 directories, 3 files
  • pomは編集しました
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.example</groupId>
  <artifactId>servlet</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>servlet Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>jakarta.servlet</groupId>
      <artifactId>jakarta.servlet-api</artifactId>
      <version>5.0.0</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.2</version>
      </plugin>
    </plugins>
  </build>
</project>
  • HttpServletクラスを継承したクラスを作ります
package org.example;

import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

public class DemoServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        var writer = resp.getWriter();
        writer.write("Hello from Jakarta Servlet 5");
    }
    
}
  • web.xmlの作成
    • 中身良くわからず、とりあえずなんとなくで書いてみる
<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  
  <servlet>
    <servlet-name>demo-servlet</servlet-name>
    <servlet-class>org.example.DemoServlet</servlet-class>
  </servlet>
  
  <servlet-mapping>
    <servlet-name>demo-servlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>
  • warの作成
$ mvn clean package
  • Jettyにデプロイします
$ cp target/servlet-1.0-SNAPSHOT.war $JETTY_BASE/webapps/demo-servlet.war
$ java -jar $JETTY_HOME/start.jar
  • 動作確認
$ curl http://localhost:8080/demo-servlet/
Hello from Jakarta Servlet 5

Eclipse Jetty を起動させてみた

Eclipse Jetty

ダウンロード

  • Jetty本体をダウンロード
  • 11.0.6 を .tgz 形式でダウンロードした
  • jetty-home-11.0.6.tar.gz というファイルがダウンロードされる
  • /opt に解凍する
$ sudo tar -xvf jetty-home-11.0.6.tar.gz -C /opt
export JETTY_HOME="/opt/jetty-home-11.0.6"

アーキテクチャ

メインコンセプト

Jetty Modules

  • Jetty Moduleは協調し一つ以上の機能を提供するJavaコンポーネント
  • Jetty ModuleはJavaAPIを使って構成できる(Javaプログラムということ?)が、設定ファイルを使って宣言的にもできる(?)
  • Jetty Moduleは依存関係がある
    • httpモジュールはserverモジュールに依存しており、serverモジュールはtheadpool,loggingモジュールに依存している
  • Jetty Moduleを有効・無効にすることでJettyの動作を変更できる
    • 例えばhttpモジュールを有効にするとHTTPリクエストは処理するが、httpsモジュールが無効であればHTTPSリクエストは処理しない
  • カスタムモジュールを作成し、動作を変更できる
  • これらの仕組みによって、必要に応じJettyのサイズを小さくできる
    • 無効にされたモジュールはロードされずメモリを使わないから

$JETTY_HOME and $JETTY_BASE

  • 複数のJettyディストリビューションを複数の場所で管理する代わりに、$JETTY_HOME によってスタンドアローンのJettyのバイナリを分離して管理できる(?)
  • 特定の環境にカスタマイズされたものを $JETTY_BASE とする(?)
  • Jetty本体の場所 -> $JETTY_HOME
  • Jettyの設定の場所 -> $JETTY_BASE
  • $JETTY_HOME は各バージョンごとに一つだが、 $JETTY_BASE はそれぞれのバージョンに対し複数あってもOK
  • 例えばデフォルトで8080でリッスンするJettyの設定を6060にしたい場合は $JETTY_HOME ではなく、 $JETTY_BASE で行う
    • こうすればJettyのバージョンを変えても設定は維持される
  • $JETTY_HOME の場所をシステム管理者とすることでファイルパーミッションの効力(機能?)を許可できる
    • この時 $JETTY_BASE は一般ユーザとできる
    • ただ、強い権限を持つユーザでサーバーを起動するのはセキュリティ上あまりよろしいことではないため、システム管理者は割り当てないほうがいいだろう

Start Mechanism

  • Jettyをスタートするメカニズムは2つの特徴がある
    • 必要なモジュールを有効にする $JETTY_BASE を設定し、構成を表示する
    • $JETTY_BASE を読み取るJVMをスタートしJettyを起動する(?)
  • $JETTY_HOME/start.jar$JETTY_BASE から起動させることでJettyがスタートする
> mkdir jetty-base
> cd jetty-base/
> java -jar $JETTY_HOME/start.jar --help
Usage:

$ java -jar $JETTY_HOME/start.jar [command] [options...]

Commands can be of two types: report commands or configuration commands.
Commands execute and then exit the JVM.
Options can be specified with or without commands.
When no command is specified, Jetty is started with the given options.
〜以下略〜
  • モジュールをリスト表示することができる
> java -jar $JETTY_HOME/start.jar --list-modules=demo

Modules [demo]:
===============

demo modules:
-------------
               demo - A meta module to enable all demo modules.
    demo-async-rest - Demo Async Rest webapp
          demo-jaas - Demo Spec webapp
         demo-jetty - Demo Jetty Webapp
          demo-jndi - Demo JNDI Resources Webapp
           demo-jsp - Demo Simple JSP Webapp
demo-mock-resources - Download and install some Demo Mock Resources
 demo-moved-context - Demonstrate a Moved Context Handler.
         demo-proxy - Demo Proxy Webapp
         demo-realm - Configure a demo authentication realm.
       demo-rewrite - Demonstrate the rewrite module.
          demo-root - Demo root webapp.
        demo-simple - Demo Simple Webapp
          demo-spec - Download and deploy the Test Spec webapp demo.
      test-keystore - Test keystore with self-signed SSL Certificate.
  • httpモジュールを追加してみる
> java -jar $JETTY_HOME/start.jar --list-modules=http

Modules [http]:
===============

connector modules:
------------------
           http - Enables a clear-text HTTP connector.
          http2 - Enables the support for the secure HTTP/2 protocol.
         http2c - Enables the support for the clear-text HTTP/2 protocol.
          https - Adds HTTPS protocol support to the TLS(SSL) Connector.
unixsocket-http - Adds an HTTP protocol support to the Unix Domain Socket connector.
> java -jar $JETTY_HOME/start.jar --add-module=http
INFO  : mkdir ${jetty.base}/start.d
INFO  : server          transitively enabled, ini template available with --add-module=server
INFO  : logging-jetty   transitively enabled
INFO  : http            initialized in ${jetty.base}/start.d/http.ini
INFO  : resources       transitively enabled
INFO  : threadpool      transitively enabled, ini template available with --add-module=threadpool
INFO  : logging/slf4j   dynamic dependency of logging-jetty
INFO  : bytebufferpool  transitively enabled, ini template available with --add-module=bytebufferpool
INFO  : mkdir ${jetty.base}/resources
INFO  : copy ${jetty.home}/modules/logging/jetty/resources/jetty-logging.properties to ${jetty.base}/resources/jetty-logging.properties
INFO  : Base directory was modified
> tree .
.
├── resources
│   └── jetty-logging.properties
└── start.d
    └── http.ini

2 directories, 2 files
  • デモウェブアプリをモジュールとして設定できるようなのでやってみる
> java -jar $JETTY_HOME/start.jar --add-module=demo-simple
INFO  : webapp          transitively enabled, ini template available with --add-module=webapp
INFO  : security        transitively enabled
INFO  : servlet         transitively enabled
INFO  : demo-simple     initialized in ${jetty.base}/start.d/demo-simple.ini
INFO  : deploy          transitively enabled, ini template available with --add-module=deploy
INFO  : mkdir ${jetty.base}/webapps
INFO  : download https://repo1.maven.org/maven2/org/eclipse/jetty/demos/demo-simple-webapp/11.0.6/demo-simple-webapp-11.0.6.war to ${jetty.base}/webapps/demo-simple.war
INFO  : Base directory was modified
  • 起動
> java -jar $JETTY_HOME/start.jar
  • 動いているらしい
> curl -v http://localhost:8080/demo-simple/
*   Trying 127.0.0.1:8080...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /demo-simple/ HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.68.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Last-Modified: Wed, 12 May 2021 06:27:22 GMT
< Content-Type: text/html
< Accept-Ranges: bytes
< Content-Length: 76
< Server: Jetty(11.0.6)
< 
<!DOCTYPE html>
<html>
  <body>
    <h2>Hello World!</h2>
  </body>
</html>
* Connection #0 to host localhost left intact
  • 起動後の $JETTY_BASE はこうなっていた
  • webappsにwarを配置すれば読み込んでくれそう
$ tree .
.
├── resources
│   └── jetty-logging.properties
├── start.d
│   ├── demo-simple.ini
│   └── http.ini
└── webapps
    └── demo-simple.war

3 directories, 4 files
  • 今日はここまで

【メモ】OAuth 2.0 におけるアクセストークンの種類

  • アクセストークンは次の2種類に分類できる
  • reference token
    • 認可サーバーでしか検証できないトークン(ランダムな文字列など)
    • リソースサーバーはトークンを受け取るたびに毎回認可サーバーにトークンの検証をリクエストしなければいけない
    • サービスをスケールさせるときに認可サーバーがボトルネックになる可能性が高い
  • self-contained token
    • 認可サーバー以外でもトークンを検証する事ができる(JWSなど)
    • リソースサーバーはトークンを受け取ると認可サーバーと通信せずに検証が可能
    • サービスをスケールさせるときに認可サーバーがボトルネックになる可能性は低い

【作業記録】mavenプラグインを作ってみる

  • 2019年ごろに kawashima さんの発表で maven プラグインを作るのはとても簡単だし、やってみましょうという発表があったのでやってみる
    • たしか生で発表をみていたはず



  • さくっとプラグインを作るには以下のpomを使う
    • 試してないけれど、mavenの動作環境はJava1.7以上のはずなので、プラグインも1.7で生成する必要がありそう
    • ただ、getting started に記載されてる pom には、以下の通り1.7の指定はない
    • 一方で archetype を使って生成すると1.7で生成されるように pom が設定される
<project>
  <modelVersion>4.0.0</modelVersion>
 
  <groupId>sample.plugin</groupId>
  <artifactId>hello-maven-plugin</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>maven-plugin</packaging>
 
  <name>Sample Parameter-less Maven Plugin</name>
 
  <dependencies>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-plugin-api</artifactId>
      <version>3.0</version>
      <scope>provided</scope>
    </dependency>
 
    <!-- dependencies to annotations -->
    <dependency>
      <groupId>org.apache.maven.plugin-tools</groupId>
      <artifactId>maven-plugin-annotations</artifactId>
      <version>3.4</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
</project>
  • mojo を作る
  • maven old java object の略(のはず)
  • 一つのゴールに紐付いていて、プラグインの中に複数定義できる
  • @Parameter アノテーションを指定すれば、パラメーターを受け取れる
    • Stringだけじゃなくてbooleanやintなどの型でも受け取れる
package org.example.demo.maven.plugin;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

/**
 * Says "hi" to the user.
 */
@SuppressWarnings("SpellCheckingInspection")
@Mojo(name = "sayhi")
public class GreetingMojo extends AbstractMojo {

    @Parameter(property = "greeting", defaultValue = "Hello, world")
    private String greeting;

    @Parameter(property = "myBoolean")
    private boolean myBoolean;

    public void execute() {
        getLog().info(greeting);
        getLog().info(Boolean.toString(myBoolean));
    }

}
  • mvn install でローカルリポジトリに入れれば、ローカルの他のプロジェクトで使用できる
  • 他のプロジェクトで使うには以下のようなpomにする
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>demo-maven-plugin-user</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.example</groupId>
                <artifactId>demo-maven-plugin</artifactId>
                <version>1.0-SNAPSHOT</version>
                <configuration>
                    <greeting>Hello, from pom</greeting>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>sayhi</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
  • 実行するとこんな感じ
$ mvn demo:sayhi
[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------< org.example:demo-maven-plugin-user >-----------------
[INFO] Building demo-maven-plugin-user 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- demo-maven-plugin:1.0-SNAPSHOT:sayhi (default-cli) @ demo-maven-plugin-user ---
[INFO] Hello, from pom
[INFO] false
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.198 s
[INFO] Finished at: 2021-08-07T21:16:57+09:00
[INFO] ------------------------------------------------------------------------
  • compileフェーズにゴールを紐づけているので、compileするとmojoも実行される
$ mvn compile
[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------< org.example:demo-maven-plugin-user >-----------------
[INFO] Building demo-maven-plugin-user 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ demo-maven-plugin-user ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ demo-maven-plugin-user ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- demo-maven-plugin:1.0-SNAPSHOT:sayhi (default) @ demo-maven-plugin-user ---
[INFO] Hello, from pom
[INFO] false
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.650 s
[INFO] Finished at: 2021-08-07T21:19:58+09:00
[INFO] ------------------------------------------------------------------------

【メモ】Mavenの依存関係について

  • Mavenの依存関係は2つある
  • Direct Dependency と Transitive Dependency (実際にこういった名前があるわけではない。2種類存在するということ)

f:id:bau1537:20210725132202p:plain

  • Direct Dependency = pomから直接指定されたモジュール
  • Transitive Dependency = 推移的に依存しているモジュール
  • どちらの依存関係もMavenが解決しクラスパスにセットしてくれる

f:id:bau1537:20210725133228p:plain

  • Transitive Dependency 内に同じものがあるときは、浅いものが選択される
  • この時、Module D のバージョンの違いなどが発生する

f:id:bau1537:20210725134032p:plain

  • Mavenのスコープを使うと話が少し複雑になる場合がある
  • Direct Dependency & Transitive Dependency が provided スコープの場合、依存解決の対象から外れる
    • なぜこのような仕様になっているかはわからん

【作業記録】paraを単体で使ってみた

  • paraを使ってみた件
  • 前回はscooldとparaを組み合わせてQAサイトをローカルに構築しました
  • 今回はpara単体で使ってみようと思います
  • 環境とかバージョンとか諸々は次のとおりです(前回と同じ)
$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.2 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
$ docker -v
Docker version 20.10.7, build f0df350
$ docker-compose -v
docker-compose version 1.25.0, build unknown
$ node -v
v16.4.2
$ npm -v
7.18.1
  • 今回もDocker、docker-composeを使っていきます
  • docker-compose.yml はこちら
version: '3.4'

services:
   para:
     image: erudikaltd/para:latest_stable
     ports:
       - "8080:8080"
     volumes:
       - type: volume
         source: paraData
         target: /para/data
       - type: volume
         source: paraLib
         target: /para/lib
       - type: bind
         source: ./para-application.conf
         target: /para/application.conf
     restart: always
     environment:
       - JAVA_OPTS=-Dconfig.file=/para/application.conf -Dloader.path=/para/lib

volumes:
  paraData:
  paraLib:
  • 前回使ったものの流用です
  • 前回同様この後のセットアップは同じなので手順は省略します

  • para-cliを使ってオブジェクトを保存してみます
  • 次のファイルを作ります
{
    "id": 1,
    "type": "demo_json",
    "data": "hello, para!"
}
  • このファイルを保存します
$ para-cli create file.json
✔ Creating file.json
✔ Created 1 objects with a total size of 0 KB.
✔ Created 1 objects.
  • idをもとに検索してみます
$ para-cli search "id:1"
[
  {
    "id": "1",
    "type": "demo_json",
    "name": "file.json",
    "stored": true,
    "indexed": true,
    "cached": true,
    "version": 0,
    "timestamp": 1625975404319,
    "appid": "para",
    "votes": 0,
    "objectURI": "/demo_json/1",
    "plural": "demo_jsons",
    "data": "hello, para!"
  }
]
  • 作成したJSONの内容が返ってきました
  • かつ、いろいろな情報が追加されているのがわかりました
  • いろいろな検索を試してみましたが、とりあえずフィールドをキーにして検索はできるみたいです
    • typeフィールドで検索
    • $ para-cli search "type:demo_json"
    • nameフィールドで検索
    • $ para-cli search "name:file.json"
    • timestampフィールドで検索
    • $ para-cli search "timestamp:1625975404319"
  • ANDなどで検索条件を追加できます
    • $ para-cli search "id:1 AND type:demo_json"
  • ワイルドカードも使えました
    • $ para-cli search "id:1 AND type:demo_*"
  • 削除を試します
$ para-cli delete --id 1
✔ Deleted objects " [ '1' ] " from Para.
$ para-cli search "id:1"
[]

【作業記録】scoold と para を使ってQAサイトをローカルに構築

環境

$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.2 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
$ docker -v
Docker version 20.10.7, build f0df350
$ docker-compose -v
docker-compose version 1.25.0, build unknown
$ node -v
v16.4.2
$ npm -v
7.18.1

それぞれを立ち上げてみる

# scoold-application.conf

### Minimal configuration ###
# the name of the application
para.app_name = "Scoold"
# the port for Scoold
para.port = 8000
# change this to "production" later
para.env = "development"
# the public-facing URL where Scoold is hosted
para.host_url = "http://localhost:8000"
# the URL of Para - can also be "https://paraio.com"
para.endpoint = "http://para:8080"
# access key for your Para app
para.access_key = "app:scoold"
# secret key for your Para app
para.secret_key = ""
# the email or identifier of the admin user - check Para user object
para.admins = "admin@domain.com"

####### Authentication #######
# enable or disable email and password authentication
para.password_auth_enabled = true

####### Misc #######
# if false, commenting is allowed after 100+ reputation
para.new_users_can_comment = true
# If true, the default space will be accessible by everyone
para.is_default_space_public = true
  • para.secret_key にはあとでシークレットキーをセットします
# para-application.conf
para.env = "development"
para.dao = "H2DAO"
para.security.allow_unverified_emails = true
  • paraのnodejsクライアントをインストールします
  • ツールの名前とバージョンはこちら
$ para-cli --version
1.15.2
  • 一度 docker-compose up で立ち上げます
# 立ち上げた後、以下のコマンドでparaから設定に必要な情報を受け取ります
$ curl localhost:8080/v1/_setup
{
  "accessKey" : "app:para",
  "message" : "Save these keys - they are shown only once!",
  "secretKey" : "H6orTyiuJJGEc0UDcsrrkprxPEYOaJTVE/Drv/oBVCTIjxH0JyZLZw=="
}
# paraに接続
$ para-cli setup
Para Access Key: app:para
Para Secret Key: H6orTyiuJJGEc0UDcsrrkprxPEYOaJTVE/Drv/oBVCTIjxH0JyZLZw==
Para Endpoint: localhost:8080
✔ New JWT generated and saved in /home/bookstore/.config/para-cli-nodejs/config.json
✔ Connected to Para server v1.39.2 on localhost:8080. Authenticated as: app para (app:para)
# アプリなるものを新しく作ります
# テナントごとにアプリがあるイメージでしょうか
$ para-cli new-app "scoold" --name "scoold"
✔ App created:
{
  "accessKey": "app:scoold",
  "message": "Save these keys - they are shown only once!",
  "secretKey": "P9vbAx1nfVS2DyQMtliSRYe5A/CgGxpI8all5yo59MOid8aiqyKcxQ=="
}
# 個々で受け取った secretKey を scoold-application.conf の para.secret_key にセットします
  • コンテナを再起動させます
  • localhost:8000 にアクセスするとscooldのページが表示されます

参考