LoginSignup
1
3

More than 3 years have passed since last update.

strapiが僕の知ってるCMSではなかったのでドキュメントの見どころ紹介

Posted at

CMSってデータベースのスキーマまで管理するのかい?

スクリーンショット 2019-11-01 0.28.20.png

とにかく言えるのは、「node rails like framework」なんて検索してる場合ではなかった。

さてドキュメントの見どころ紹介。

チュートリアル

起動したらあとは画面上でポチポチやってるだけなのだ。。
https://strapi.io/documentation/3.0.0-beta.x/getting-started/quick-start-tutorial.html

多対多のリレーション定義

中間テーブル名はcategories_restaurants__restaurants_categories。

スキーマ:

sqlite> .schema categories_restaurants__restaurants_categories
CREATE TABLE `categories_restaurants__restaurants_categories` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `category_id` int null, `restaurant_id` int null);
sqlite> select * from categories_restaurants__restaurants_categories;
1|1|1
2|2|1

ロールとパーミッション

ここではfindとfindoneのみ許可。
クリックするとAdvanced settingsに表示されるけど、 GET /resourceGET /resource/:id

userに関してはmeのみ許可などもできるようだ。
制御に関連を利用したい場合とかについてはこんな感じの議論があった。現状では専用のコントローラを用意することになるのかなと。

それにしても、

think of an HR system where normal employees can only see name and email (of the object "employee") whereas an HR can see the personal address and bank account.
たとえば、通常の従業員は名前とEmailしか見れないが、HRは住所と銀行口座が見れるというような。

うん。そういうきめ細かいことを簡単にやっちゃいたいのよね。

生成されたAPI叩くとこ

ちゃんとjsonになってます。

ディレクトリ構造

modelとかcontrollerとかserviceとかあります。
馴染み深〜い。

コントローラ

https://strapi.io/documentation/3.0.0-beta.x/concepts/controllers.html
ビジネスロジックを書きます。

モデル

https://strapi.io/documentation/3.0.0-beta.x/concepts/models.html
スクリーンショット 2019-11-01 0.45.01.png
jsの方はライフサイクル管理。フィールドの設定やらには .settings.json という感じ(ただしmongo以外はDBMSのほうですべしとある)。

クエリ

ORMはBookshelf.js
https://bookshelfjs.org

ポリシー

リクエストがコントローラに到達する前にisAdminとかisAuthenticatedとかのフィールドを設定できる。
ミドルウェア? いや、違うっぽい?

ミドルウェア

await next();
ctx.set('X-Response-Time', delta + 'ms');

みたいな。オニオンにできるのね。
※ポリシーもオニオン
https://strapi.io/documentation/3.0.0-beta.x/concepts/policies.html#advanced-usage

こっちのミドルウェアは strapi.app.use してるのが違いなのだと思う。。
ポリシーはroutesで設定。

感想

とりあえず感想を書けば締まると思っている。

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3