ããã¯ãããã¾ã§Railsã®å¤ãè¯ãMVCãªéçºä½å¶ããç¥ããªãã£ãããã¯ã¨ã³ãéçºè
ããç°å¢ãå¤ãã£ã¦ããã³ãã¨ã³ãéçºãå¦ã°ãããããªããªã£ãè
ã®è¨é²ã§ãã
æ´å²çã«æ£ããäºå®ãæ¸ãããã®ã§ã¯ãªããç§å人ã®ç解ãæ´çããããã®å¦æ³æ¥è¨ã§ãã
Â
ç§ã¯ããã¾ã§ã¯Webã¢ããªã®éçºã°ãããã£ã¦ãã¦ãRailsã§HTMLãã³ãã¬ã¼ãã¨ã³ã¸ã³ä½¿ã£ã¦viewãä½ãã¹ã¿ã¤ã«ã§ããéçºãã¦ãã¾ããã§ããã
Â
ãããããã¤ãã£ãããã³ãã¨Webããã³ã両æ¹ãããã¢ããªã±ã¼ã·ã§ã³ãéçºããã¦ããã¨ãããè¦ã¦ãããäºãæãã¤ãã¾ããã
Â
ãWebããã³ãããã¤ãã£ãããã³ãã®ããã«éçºã§ããã°ãããã¯ã¨ã³ãã¨ã³ã¸ãã¢ã¯ããã¯ã¨ã³ãã«ãããã³ãã¨ã³ãã¨ã³ã¸ãã¢ã¯ããã³ãã¨ã³ãã«åæ¥ã§ãã¦ãéçºãããããªãã®ã§ã¯ï¼ã
Â
ãã®æ°ä»ããè¶ éè¦ã§ããããã®ã¤ã¡ã¼ã¸ãæã¦ããããã§ããã³ãéçºã®æ義ãã¹ã«ã¹ã«å ¥ã£ã¦ãã¾ããã
Â
Railsã¯ãã«ã¹ã¿ãã¯ãã¬ã¼ã ã¯ã¼ã¯ãªã®ã§ãRailsã§HTMLãçæãã¦è¿ããã¨ãã§ãã¾ããããã®éçºä½å¶ã ã¨ããããã¯ã¨ã³ãã¨ã³ã¸ãã¢ã¯ãå¾æãªããã¯ã¨ã³ãã沢山æ¸ãã¦ãä¸å¾æãªããã³ãã¨ã³ããã¡ãã£ã¨æ¸ããããã³ãã¨ã³ãã¨ã³ã¸ãã¢ã¯å¾æãªããã³ãã¨ã³ãã沢山æ¸ãã¦ãä¸å¾æãªããã¯ã¨ã³ããã¡ãã£ã¨æ¸ãããã¨ãããã¨ãèµ·ãã£ã¦ããããã«æãã¾ãã
ã ãã ãã¨ããã¡ãã£ã¨ä¸å¾æãªäººãæ¸ããã³ã¼ãããå¢ãã¦ããã¾ããã¬ãã¥ã¼ã§ææããããã°è¯ãã®ã§ããããªããªãå®ç§ã«ã¯ããã¾ããã
Â
ãããRailsã®Vé¨åãå¼ãå¥ããã¦ãããã³ãã¨ã³ããå¾æãªã¨ã³ã¸ãã¢ã«éçºãä»»ãããã¨ãã§ããã°ãRailsã¯APIã ãã§ãããªãããã¤ãã£ãããã³ããWebããã³ããåãããã«APIãæä¾ããå½¢ã§éçºã§ãã¾ãã
Â
ã©ããããããå®ç¾ããã®ãSPA(ã·ã³ã°ã«ãã¼ã¸ã¢ããªã±ã¼ã·ã§ã³)ã¨ããäºãªã®ããªã¨æãã¾ã(å¤åééã£ã¦ã)ã
ã ããããRailsã§APIã¢ã¼ããã§ããããPWAã ã¨ããã話ãåºã¦ããã®ããªã¨æ³åãã¾ãã
Â
ããã¦SPAãä½ããããReactãVueãçãä¸ãã£ãã¨äºæ³ãã¾ãããã®SPAãS3ã¨ããªããããæãã®ãã©ãããã©ã¼ã (ãããNetlifyã¨ããªã®ãï¼)ã«ãããã¤ããã°ããµã¼ãã¼ã管çããã¨ãç°¡åãªã¢ããªãªãä½ããããLambdaã¨ãã¨çµã¿åãããã°çµæ§ãªãã¨ã¾ã§åºæ¥ã¡ããã¾ã(ãããAWS amplify?)ãããããLinuxãµã¼ãã¼ãç«ã¦ããããªãã¦ãããã·ã¥ã¢ãããµã¼ãã¹ã¨ããä½ãã¦ãã¾ãã®ã§ããµã¼ãã¼ã¬ã¹ã¨ããå«ã°ãã¦ããã®ããªãï¼
Â
ãã®SPAãç´°ããè¨ãã¨è²ã ãããããããããã§ãã
Â
ä¾ãã°ãã©ã¦ã¶ã§ãã¼ã¸ãéããã¨ãã«JSãèµ·åãã¦HTMLãæ§ç¯ããã·ã³ãã«ãªæ¹æ³ãCSR(ã¯ã©ã¤ã¢ã³ã ãµã¤ã ã¬ã³ããªã³ã°)ã¨è¨ãããã§ããã ãããã®ãã¨ã¯CSRã§è¡ããããcreate-react-appãåºã¦ãã¦å¦ç¿ã³ã¹ããä¸ãã£ã¦ããã®ã§ãä»ãçµæ§ä½¿ããã¦ãã®ããªã¨äºæ³ãã¾ãã
Â
ããããªããGoogleã¯ãã¼ã©ã¼ãJSãå®è¡ãããããªããå¾®å¦ãªææããã£ãã®ããæåã®JSå®è¡æã®ã©ã°ãæ°ã«ãã¦ãããµã¼ãã¼ãµã¤ãã§ReactãªãVueãªããå®è¡ãã¦HTMLãçæããææ³ãåºã¦ãã¾ããããããNext.js(React)ã¨ãNuxt.js(Vue)ã¨ãããã¨ããªã¨æãã¾ãããããSSR(ãµã¼ãã¼ ãµã¤ã ã¬ã³ããªã³ã°)ã¨è¨ãããã§ãã
Â
Next.jsã®æ¹ãã¡ãã£ã¨è§¦ã£ãã ãã§ãããåçç»åçæãå®è£ ããçµé¨ããããnext/imageã ãã§ãããªã便å©ããã§ãã
ããã¯ãlibvipsã使ã£ã¦åçã«ç»åãçæãã¦ããã©ã¦ã¶æ¯ã«æé©ãªå½¢å¼ã§ãã¡ã¤ã«ãä½ãããã£ãã·ã¥ç¨ã®ãããã¼ãããæãã«ãã¦ããªããªãå°ç¨ãµã¼ãã¹(Vercelï¼)ã«ãããã¤ããã°çæãããã¡ã¤ã«ããã£ãã·ã¥ãã¦ããã¾ãã
ããã ãã§ãå°å ¥ããåæ©ã«ãªãããã§ãã触ã£ã¦ã¿ãæããS3ã®ãã¡ã¤ã«ã¨ãã§ããã¡ã¤ã³ããè¨å®ããã°ãªãã§ãããããã
ãã ãããã®ç»åçææ©è½ã¯ãã«ãæã§ã¯ãªãç»åã¸ã®ãªã¯ã¨ã¹ãããµã¼ãã¼ä¸ã«æ¥ãã¨ãã ãã«ä½¿ããã®ã§ãSSRã§ã¯ä½¿ãã¦ãå¾è¿°ããSSGã§ã¯ä½¿ããªãããã§ãã
Â
ãã¦ããããªSSRããGoogleã¯ãã¼ã©ã¼ãJSãå®è¡ãã¦ãããããã«ãªã£ãããCDNãä¸è¬çã«ãªã£ããããããããµã¼ãã¼å´ã®è¦ç´ ãå¢ããã®ã§ãå®è£ ãè¤éã«ãªã£ã¦ãã¾ããã¡ã§ãããããã§æ°ããªçã¨ãã¦ãäºããã«ãæ(ãããã¤æ)ã«DBãªããè¦ã¦ãããããHTMLãçæãã¦ããã¦ããããCDNãªãã§éçãã¡ã¤ã«ãé ä¿¡ããã°ããµã¼ãã¼ã®ããã»ã¹ããããªããããªããªãDBããããªãããæ¢ã«ã¬ã³ããªã³ã°ããã¦ãããã表示ãæ©ããã§ããäºãããã¨ãªã£ãã®ãSSG(ã¹ã¿ãã£ã㯠ãµã¤ã ã¸ã§ãã¬ã¼ã¿ã¼)ãªã®ããªã¼ã¨äºæ³ãã¾ãã
ãããNext.jsã®ä»ã®å£²ãã£ã½ãã§ããCSRã«ä¼¼ã¦ãã¾ãããHTMLã®ãããããçæ度åãããCSRã0ã ã£ãã®ãSSGã§80ã100ã«ãªã£ãã¤ã¡ã¼ã¸ã§ãããã¡ããAPIãã¯ã©ã¤ã¢ã³ããµã¤ãããå©ãã¦åçã³ã³ãã³ãã追å ãããã¨ãã§ãã¾ãããªãããã®è¾ºããJamstackã¨è¨ãããããã£ã½ãæãããã¾ããããã°ã¨ãã»ã¨ãã©SSGã§ããããã§ãã
Â
æ´ã«ISGãISRãªãã¦ã®ãããã£ã½ãã§ãããã¾ã ã¾ã ãã£ããã¢ããä¸ã§ããããÂ
Â
ãã¦ãã¦ããããªãã¨ãæè¿å¦ãã§ã¿ã¦ãã¾ããå°ãNext.jsã¢ããªã±ã¼ã·ã§ã³ãä½ã£ã¦ã¿ã¦ãæãªããã®Railsã¢ããªã±ã¼ã·ã§ã³ã«å¯¾ããèãæ¹ãå¤ãããããããæ代ã«è¿½ãã¤ãã¦ãªããã¨ãèªè¦ã§ããã¬ãã«ã«ã¯ãªããããï¼ã¨æãã¾ããã
ããã¾ã§ä½ã£ã¦ãããã®ã¯ããµã¼ãã¼ãµã¤ãã§ã»ã¼åãHTMLãä½ã£ã¦è¿ããã®ãªã®ã§ãæè¿ã®ããã³ãäºæ ãããããç¡é§ãå¤ãã®ããã¨æãã¦ãã¾ããã
ã¾ããNext.jsãcreate-next-appã§ä½ã£ã¦ã¿ãã¨ãé©ãã»ã©ç°¡åã«ã³ã³ãã³ããä½ãã¦ãã¾ãã¾ããããã³ãã¯ããã£ããã ã£ãç§ããç°¡åãªã¢ã³ã±ã¼ããµã¤ãã¿ãããªãã¤ãªãä½ããã®ã§ç¢ºãã§ãã
Next.jsã¯ã«ã¼ãã£ã³ã°ãç°¡åã«(ãã¡ã¤ã«ãã¹ãåãã ã)ã§ããã®ã§ãææ©VãCãããã³ãã§ã§ãã¦ãã¾ãã¾ãã
ããã¦ãã©ããSSRãããªãããã®nodeãµã¼ãã¼ããprismaãªãã§DBãå©ãã¦åçã³ã³ãã³ããè¿ããã°1ããã»ã¹ã ãã§ããããèªè¨¼ãFirebase AuthenticationãAuth0ãªããã§ä½ãã¦ãã¾ãã¾ãã
ãããªãã¨ããã¯ãRailsã¯ãããªãï¼ãã¿ãããªæèã«ãªã人ãç¾ãã¦ããããããªããªã¨æãæ°æã¡ãç解ã§ãã¾ãã
ãã¡ããRailsã§HTMLãçæããæ¹æ³ããç¶æ³ã«ãã£ã¦pros/consãããã¨ã¯æãã¾ãããèªåãè¦ãªãããã«ãã¦ãããã®ã®å¤§ãããæ¥ã«ç¥ã£ã¦ãé©ãã°ããã§ãã
ã£ã¦ããããã¯ãç§ã¨ãã¦ã¯ãããã¯ã¨ã³ãã¨ã³ã¸ãã¢ã¨ã¯ï¼èªåã®åå¨ä¾¡å¤ã¯ï¼ã¿ãããªæ°æã¡ã§ãã
Â
ãããããæ¹ãã¦ãã©ããã£ã¦ã¢ããªãä½ãã®ãããèãç´ãã¦ã¿ããã¨æãã¾ãã