Files
PixelDocs/assets/flash_advanced_fullstack-development.md.B124NtWL.js
T
2025-02-27 21:46:56 +00:00

30 lines
16 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{_ as e,c as a,a0 as i,o as t}from"./chunks/framework.p2VkXzrt.js";const n="/assets/flash-fullstack.D96XNhET.png",u=JSON.parse('{"title":"🌐 Fullstack Development with Flash","description":"","frontmatter":{"banner_title":"Flash - Fullstack Development","banner_description":"Build fullstack apps with Flash, frontend and backend in one jar.","head":[["meta",{"name":"twitter:image","content":"/assets/banner-cards/flash-advanced-fullstack-development.png"}],["meta",{"name":"twitter:image:src","content":"https://docs.pixel-services.com/assets/banner-cards/flash-advanced-fullstack-development.png"}],["meta",{"name":"twitter:card","content":"summary_large_image"}],["meta",{"name":"twitter:image:height","content":"1280"}],["meta",{"name":"twitter:image:width","content":"669"}],["meta",{"name":"twitter:description","content":""}]]},"headers":[],"relativePath":"flash/advanced/fullstack-development.md","filePath":"flash/advanced/fullstack-development.md"}'),l={name:"flash/advanced/fullstack-development.md"};function o(r,s,p,h,d,c){return t(),a("div",null,s[0]||(s[0]=[i('<h1 id="🌐-fullstack-development-with-flash" tabindex="-1">🌐 Fullstack Development with Flash <a class="header-anchor" href="#🌐-fullstack-development-with-flash" aria-label="Permalink to &quot;🌐 Fullstack Development with Flash&quot;"></a></h1><p>Fullstack development involves building both the <strong>front-end</strong> (user interface) and <strong>back-end</strong> (server logic, database) of a web application. A fullstack developer is responsible for the entire application, ensuring a smooth connection between the two layers.</p><p>Popular fullstack frameworks include:</p><ul><li><a href="https://rubyonrails.org" target="_blank" rel="noreferrer">Ruby on Rails</a> (Ruby)</li><li><a href="https://www.djangoproject.com" target="_blank" rel="noreferrer">Django</a> (Python)</li><li><a href="https://laravel.com" target="_blank" rel="noreferrer">Laravel</a> (PHP)</li></ul><h2 id="⚡-fullstack-development-with-flash" tabindex="-1">⚡ Fullstack Development with Flash <a class="header-anchor" href="#⚡-fullstack-development-with-flash" aria-label="Permalink to &quot;⚡ Fullstack Development with Flash&quot;"></a></h2><p>Developing and packaging a fullstack application can be complex, but <strong>Flash</strong> simplifies the process with built-in tools and <strong>quality-of-life features</strong>. With Flash, you can:</p><ul><li>Serve both <strong>frontend</strong> and <strong>backend</strong> from a single application.</li><li>Bundle everything into a <strong>single JAR file</strong> for easy deployment.</li><li>Leverage HDIs for <strong>clean, modular and maintainable route logic</strong>.</li></ul><p><img src="'+n+`" alt="Flash Fullstack Development"></p><h2 id="🚀-serving-frontend-with-flash" tabindex="-1">🚀 Serving Frontend with Flash <a class="header-anchor" href="#🚀-serving-frontend-with-flash" aria-label="Permalink to &quot;🚀 Serving Frontend with Flash&quot;"></a></h2><p>Flashs <strong>dynamic file server</strong> enables seamless fullstack development by allowing you to serve frontend assets alongside backend logic. This is made possible by the <code>RESOURCESTREAM</code> source type, which serves files from the JARs resources folder.</p><h3 id="✅-deployment-workflow" tabindex="-1">✅ Deployment Workflow <a class="header-anchor" href="#✅-deployment-workflow" aria-label="Permalink to &quot;✅ Deployment Workflow&quot;"></a></h3><p>The recommended workflow for packaging a fullstack Flash application:</p><ol><li><strong>Compile</strong> the frontend application (React, Vue, Angular, etc.).</li><li><strong>Place</strong> the compiled files inside the <code>resources</code> folder.</li><li><strong>Build</strong> the JAR file with both frontend and backend code.</li><li><strong>Deploy</strong> the JAR, serving both frontend and backend seamlessly.</li></ol><p>This approach works for any frontend framework that compiles to static files, such as:</p><ul><li><strong>React</strong> (<code>npm run build</code>)</li><li><strong>Vue.js</strong> (<code>npm run build</code>)</li><li><strong>Angular</strong> (<code>ng build --prod</code>)</li></ul><h2 id="❔-setting-up-a-fullstack-flash-application" tabindex="-1">❔ Setting up a Fullstack Flash Application <a class="header-anchor" href="#❔-setting-up-a-fullstack-flash-application" aria-label="Permalink to &quot;❔ Setting up a Fullstack Flash Application&quot;"></a></h2><p>To get started with fullstack development using Flash, you will first need to choose a frontend framework and set up the build process to compile the frontend assets. This guide will cover only some of the most popular javascript frontend build tools, but the process is similar for others.</p><h3 id="🛠️-setting-up-the-frontend-build-process" tabindex="-1">🛠️ Setting up the Frontend Build Process <a class="header-anchor" href="#🛠️-setting-up-the-frontend-build-process" aria-label="Permalink to &quot;🛠️ Setting up the Frontend Build Process&quot;"></a></h3><div class="warning custom-block"><p class="custom-block-title">WARNING</p><p>When building a frontend application with a javascript framework that will be served from a subdirectory (e.g., <code>/app</code>), you need to specify the homepage in the <code>package.json</code> file. This ensures that the frontend assets are correctly loaded from the subdirectory. Using a subdirectory and forgetting to set the homepage will result in broken asset links and a potentially non-functional frontend.</p><div class="language-json vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">json</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">{</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> &quot;homepage&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;/your-subdirectory&quot;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div></div><ul><li><p><code>Vite</code> :</p><details class="details custom-block"><summary>Click to expand</summary><ol><li>Install Vite on your project if it&#39;s not already installed or scaffold a new Vite project (follow the <a href="https://vite.dev/guide/#scaffolding-your-first-vite-project" target="_blank" rel="noreferrer">official guide</a>).</li><li>Edit the <code>vite.config.js</code> or <code>vite.config.ts</code> build section to output the compiled files to the <code>resources/frontend</code> folder of your Flash project (see example below).</li></ol><div class="language-typescript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">typescript</span><pre class="shiki shiki-themes github-light github-dark has-diff vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // ...</span></span>
<span class="line diff add"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> path </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;path&#39;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> export</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> default</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> defineConfig</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">({</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // ...</span></span>
<span class="line"></span>
<span class="line diff add"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> build: { </span></span>
<span class="line diff add"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> outDir: path.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">resolve</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(__dirname, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;..path/to/your/src/main/resources/frontend&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">), </span></span>
<span class="line diff add"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> emptyOutDir: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">true</span></span>
<span class="line diff add"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }, </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> });</span></span></code></pre></div><ol start="3"><li>The output of your Vite build will be placed in the <code>resources/frontend</code> folder of your Flash project, ready to be packaged into the JAR file.</li></ol></details></li><li><p><code>Parcel</code></p><details class="details custom-block"><summary>Click to expand</summary><ol><li>Install Parcel on your project if it&#39;s not already installed or scaffold a new Parcel project (follow the <a href="https://parceljs.org/getting-started/webapp/" target="_blank" rel="noreferrer">official guide</a>).</li><li>Edit the Parcel build command to output the compiled files to the <code>resources/frontend</code> folder of your Flash project (see example below).<div class="language-json vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">json</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">{</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> &quot;scripts&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: {</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> &quot;build&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;parcel build src/index.html --out-dir ../path/to/your/src/main/resources/frontend&quot;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div></li><li>The output of your Parcel build will be placed in the <code>resources/frontend</code> folder of your Flash project, ready to be packaged into the JAR file.</li></ol></details></li></ul><h3 id="🛜-serve-the-frontend-with-flash" tabindex="-1">🛜 Serve the Frontend with Flash <a class="header-anchor" href="#🛜-serve-the-frontend-with-flash" aria-label="Permalink to &quot;🛜 Serve the Frontend with Flash&quot;"></a></h3><p>Once you have compiled the frontend assets and placed them in the <code>resources/frontend</code> folder, you can serve them using Flash&#39;s dynamic file server. This server will serve the frontend assets from the JAR&#39;s resources folder.</p><div class="info custom-block"><p class="custom-block-title">INFO</p><p>NOTE: The following example is assuming you plan to serve the frontend from the root path (<code>/</code>). If you plan to serve the frontend from a subdirectory (e.g., <code>/app</code>), you will need to adjust the endpoint path accordingly by adding a trailing <code>/*</code>.</p></div><div class="language-java vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">java</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">public</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> class</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Example</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> public</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> static</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> void</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">String</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[] </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">args</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> FlashServer server </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> FlashServer</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">8080</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> server.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">serveDynamic</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;/*&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> DynamicFileServerConfiguration</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> true</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;frontend&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// points to the resources/frontend folder</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;index.html&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SourceType.RESOURCESTREAM</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ));</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> server.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">start</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><h3 id="🚀-package-and-deploy-your-app" tabindex="-1">🚀 Package and Deploy your app! <a class="header-anchor" href="#🚀-package-and-deploy-your-app" aria-label="Permalink to &quot;🚀 Package and Deploy your app!&quot;"></a></h3><p>With the frontend and backend code in place, you can now build the JAR file and deploy it to your server. The JAR file will contain both the frontend and backend code, making it easy to deploy and run your fullstack application.</p><p>All you&#39;ve left to do is run the jarfile on any machine that has Java installed, and your fullstack application will be up and running!</p>`,27)]))}const g=e(l,[["render",o]]);export{u as __pageData,g as default};