๐Ÿš€ Strapi = ์˜คํ”ˆ์†Œ์Šค Headless CMS

๋ง์ด ์ฐธ ์–ด๋ ต๋‹ค... strapi๊ฐ€ ๋ญ˜๊นŒ? ์™œ ํ•„์š”ํ•จ?

์ž…์‚ฌ 9๊ฐœ์›” ์ฐจ์— ์ ‘์–ด๋“ค์–ด๊ฐ€๋Š”๋ฐ, ๋ฆฌ์•กํŠธ / ๋„ฅ์ŠคํŠธ js ๊ณต๋ถ€ํ•˜๋‹ค ๋ณด๋ฉด ๋ฐ์ดํ„ฐ๋ฅผ ๋ถˆ๋Ÿฌ์™€์„œ ๋ฟŒ๋ ค์ฃผ๊ณ , ์ด๊ฒƒ ์ €๊ฒƒ ํ…Œ์ŠคํŠธ ํ•˜๊ณ ์‹ถ์–ด์ง€๋Š”๊ฒŒ ๋งŽ์•„์ง„๋‹ค. ํ•˜์ง€๋งŒ ๋ฐ์ดํ„ฐ๋Š” ํ•œ์ •์ ์ด๊ณ , ํ…Œ์ŠคํŠธ ํ•˜๊ธฐ์—๋Š” ๋ถ€์กฑํ•˜๋‹ค.

๊ทธ๋ž˜์„œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์ง์ ‘ ๋งŒ๋“ค์ž๋‹ˆ ๊ณต๋ถ€ํ•ด์•ผ ํ•˜๋Š” ๊ฒƒ๋“ค์ด ๋Š๋ฏ€๋Š๋ฏ€ ๋„ˆ~~~๋ฌด ๋งŽ๋‹ค. ์žฅ๊ณ , ๋ชฝ๊ณ DB, Node.js ์„œ๋ฒ„ํ™˜๊ฒฝ ๊ตฌ์ถ•.. ๋ฆฌ์•กํŠธ์™€ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ, ๋„ฅ์ŠคํŠธ, ํ”„๋ก ํŠธ์—”๋“œ ํ”„๋ ˆ์ž„์›Œํฌ์™€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋„ ๋„˜์ณ๋‚˜๊ณ  ๊ณต๋ถ€ํ•ด์•ผ ํ•˜๋Š” ๊ฒƒ๋“ค์ด ํƒœ์‚ฐ๊ฐ™์€ ์ƒํ™ฉ์—์„œ... ๊ทธ๊ฒƒ ๊นŒ์ง€ ๊ณต๋ถ€ํ•˜๊ธฐ ๋ฒ…์ฐธ... (ํ•˜๊ธฐ์‹œ์ก..๐Ÿ™ˆ)

๊ทธ๋ž˜์„œ api๋งŒ ์–ด๋–ป๊ฒŒ ์™์™ ๋นผ๋‚ด์„œ ์“ธ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์ด ์—†์„๊นŒ.. ์ƒ๊ฐํ•˜๊ณ  ์žˆ์„ ๋•Œ strapi๊ฐ€ ๋‚˜ํƒ€๋‚จ..

๐Ÿš€ ๋‚ ์•„๋ผ Strapi

๐Ÿ’ž Strapi๋ž€?

Bootstrap + API๋ฅผ ์ค„์—ฌ์„œ Strapi๋ผ๊ณ  ํ•œ๋‹ค. Strapi๋Š” Node.js ์›น ํ”„๋ ˆ์ž„์›Œํฌ ์ค‘ ํ•˜๋‚˜์ธ Koa ๊ธฐ๋ฐ˜์œผ๋กœ ๊ตฌํ˜„๋˜์—ˆ์œผ๋ฉฐ, ํ’€ ์ปค์Šคํ„ฐ๋งˆ์ด์ง•์ด ๊ฐ€๋Šฅํ•œ ๊ฐœ๋ฐœ์ž ์šฐ์„ (Developer-first) ์˜คํ”ˆ์†Œ์Šค Headless CMS์ด๋‹ค.

โ“ Headless CMS๋ž€?

๋ง์ด ์ฐธ ์–ด๋ ต๋‹ค. CMS๋ž€ Content Management System์˜ ์•ฝ์ž๋กœ, ์ฝ˜ํ…์ธ  ๊ด€๋ฆฌ๋งŒ์„ ์œ„ํ•œ ์„œ๋น„์Šค์ด๋‹ค. ๊ธฐ์กด CMS๋Š” ๋ทฐ์™€ ์ฝ˜ํ…์ธ ๊ฐ€ ๊ฒฐํ•ฉ๋˜์–ด ์žˆ์ง€๋งŒ Headless CMS๋Š” ๋‚ด๊ฐ€ ์›ํ•˜๋Š” ๊ธฐ์ˆ ์Šคํ…์„ ์‚ฌ์ดํŠธ๋กœ ๊ตฌ์„ฑ ํ•  ์ˆ˜ ์žˆ๋‹ค.

โ— Strapi ์žฅ์ 

  • ๋น ๋ฅธ ๊ฐœ๋ฐœํ™˜๊ฒฝ ๊ตฌ์ถ•
  • ๋†’์€ ํ™•์žฅ์„ฑ, ์˜คํ”ˆ์†Œ์Šค ์ƒํƒœ๊ณ„๊ฐ€ ํ™œ๋ฐœ
  • ๊ตฌ๊ธ€ ๋กœ๊ทธ์ธ ๋“ฑ 15๊ฐœ์˜ ์ธ์ฆ Provider

๋“ฑ๋“ฑ ๋‹ค๋ฅธ๊ฒƒ๋“ค์€ ์–ด๋ ค์šด ๋ง๋“ค์ด ๋งŽ์Œ.. ๋‚˜์ค‘์— ๊ณต๋ถ€ํ•ด๋ณผ๊ป˜...ใ…Žใ…Ž

๐Ÿ’ž Strapi install

npx create-strapi-app@latest direactory-name --quickstart
yarn create strapi-app direactory-name --quickstart

์‹คํ–‰ํ• ๋•Œ๋Š”

yarn run develop

๐Ÿ’ž Strapi ์‚ฌ์šฉ๋ฐฉ๋ฒ•

์„ค์น˜ํ•˜๋ฉด http://localhost:1337/admin ์œผ๋กœ ๋“ค์–ด๊ฐ€๋ผ๋Š” ๋ฌธ๊ตฌ๊ฐ€ ๋œธ.
๋“ค์–ด๊ฐ€๋ฉด ์ด๋Ÿฐ ํŽ˜์ด์ง€๊ฐ€ ๋ณด์ž„.

  • Content Manager : ์–ด๋–ค ๋ฐ์ดํ„ฐ ์นดํ…Œ๊ณ ๋ฆฌ๊ฐ€ ์žˆ๋Š”์ง€ ๋ณด์—ฌ์ง.
  • Content-Type Builder : ๋ฐ์ดํ„ฐ ์ง์ ‘ ์‚ฝ์ž…ํ•˜๋Š” ์นดํ…Œ๊ณ ๋ฆฌ
  • Media Libarary : ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ ๋ชฉ๋ก

๐Ÿ’ž Strapi + Cloudnary

ํ•˜ strapi ๋ฒ„์ „์ด ๋ฐ”๊ปด์„œ ํ•œ๋™์•ˆ ์„ค์ •์ด ์•ˆ์˜ฌ๋ผ์™€์„œ ์• ๋จน์Œ..
https://strapi.io/blog/add-cloudinary-support-to-your-strapi-application ์š”๊ธฐ๋ณด๊ณ  ๋”ฐ๋ผํ•˜๋ฉด๋จ,

โ— ๋ฐ์ดํ„ฐ ๋ชจ๋‘ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ

์—ฌ๊ธฐ์„œ http://localhost:1337/api/events ๋กœ ๋ถˆ๋Ÿฌ์˜ค๋ฉด

์ด๋Ÿฐ์‹์œผ๋กœ ๋ฐ์ดํ„ฐ๊ฐ€ ๋“ค์–ด์˜จ๋‹ค. ๊ทธ๋ž˜์„œ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌํ•ด์„œ ์˜ˆ์˜๊ฒŒ ๊ฐ€๊ณตํ•ด์„œ ์จ์•ผํ•œ๋‹ค. ๋ฐ๋ฐ์ดํ„ฐ ๊ฐ€๊ณต์ฒ˜๋ฆฌ ํ•˜๋Š” ๋ฐฉ๋ฒ•์€

  • ํ•˜๋“œ์ฝ”๋”ฉ์œผ๋กœ ์ง์ ‘ ๋นผ๋‚ด์„œ page์— ์ „๋‹ฌํ•˜๋Š” ๋ฐฉ๋ฒ•.
  • axios๋กœ ์š”์ฒญ ํ›„ interceptors๋กœ ๊ฐ€๋กœ์ฑ„์„œ ํŽ˜์ด์ง€์— ์ „๋‹ฌํ•ด ์ฃผ๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  http://localhost:1337/api/events๋กœ ์š”์ฒญํ•˜๋ฉด, ์ด๋ฏธ์ง€๋ฅผ ํฌํ•จํ•œ ํฌ๋งท ์ •๋ณด๊ฐ€ ๋“ค์–ด์™€ ์žˆ์ง€ ์•Š๋Š”๋‹ค.,, ใ… ใ…  ๊ทธ๋ž˜์„œ ์ฐพ์•„๋ณด๋‹ˆ ์ฟผ๋ฆฌ ํ•˜๋‚˜๋ฅผ ์ถ”๊ฐ€ํ•ด์„œ ๋ณด๋‚ด์•ผ ํ•œ๋‹ค.

`http://localhost:1337/api/events?populate=*`

์ด๋ ‡๊ฒŒ ์š”์ฒญํ•ด์•ผ ๋ชจ๋“  ์ •๋ณด๊ฐ€ ์ž˜ ๋“ค์–ด์™€ ์žˆ๋‹ค! ๊ฐ•์˜ ๋“ค์„ ๋•Œ ๋ฒ„์ „์ด๋ž‘, ์ง€๊ธˆ ๋งŽ์ด ๋ฐ”๋€Œ์–ด์„œ 3 ๋‹ฌ ์ „ ์ฏค ๋“ค์„ ๋–„๋Š” ์• ๋จน์—ˆ์—ˆ๋Š”๋ฐ 2์›”๋‹ฌ์— strapi ์‚ฌ์ดํŠธ์— ์—…๋Žƒ์ด๋˜์„œ ํ•œ๊ฒฐ ์ˆ˜์›”ํ•จ ใ… ใ… ใ… 

โ— ํ•„ํ„ฐ๋ง ๋ฐ์ดํ„ฐ ์š”์ฒญ

์š”๊ฒƒ๋„ ๋ฒ„์ „ ๋ฐ”๋€Œ๋ฉด์„œ ๋ฐ”๋€œ!

๊ณตํ™ˆ์˜ˆ์‹œ

const qs = require('qs');
const query = qs.stringify({
  filters: {
    username: {
      $eq: 'John',
    },
  },
}, {
  encodeValuesOnly: true,
});
await request(`/api/users?${query}`);
// GET /api/users?filters[username][$eq]=John

๋งŒ์•ฝ Throwback Thursdays with DJ Manny Duke ๋„ค์ž„์„ ๊ฐ–๊ณ  ์žˆ๋Š” ์ •๋ณด๋ฅผ ์ฐพ๊ณ  ์žˆ๋‹ค๋ฉด,

http://localhost:1337/api/events?filters[name][$eq]=Throwback Thursdays with DJ Manny Duke

์ด๋ ‡๊ฒŒ ์š”์ฒญํ•ด์•ผ ํ•œ๋‹ค.

์ฟผ๋ฆฌ ๋งค๊ฐœ๋ณ€์ˆ˜(์ž์ฃผ ์‚ฌ์šฉ)

  • $eq : ๊ฐ™์Œ
  • $contains : ํฌํ•จ
  • $notContains : ํฌํ•จํ•˜์ง€ ์•Š์Œ
  • $startsWith : ์‹œ์ž‘
  • $endWith : -๋กœ ๋๋‚จ

์ž์„ธํ•œ ์ •๋ณด => strapi filter ์‚ฌ์ดํŠธ

์•„ ๊ทผ๋ฐ ๋ ˆ์•Œ ๊ฐœํŽธํ•œ๊ฑฐ๊ฐ™์Œ.


์ถœ์ฒ˜ : ๋”ํ•‘ํฌํ์ปดํผ๋‹ˆ ๊ธฐ์ˆ ๋ธ”๋กœ๊ทธ - strapi 1๋…„์ด๋ฉด ํ’€์Šคํ…์„ ์Š๋Š”๋‹ค.

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ