Organize your Polaris Code using PSHTML module

I am back after a couple of “Amstel” to demo structuring the Polaris code using PSHTML module. IMHO PSHTML is made for Polaris! It’s such great module which couples with web apps built using Polaris. Navigate to the hyper link if you are new to Polaris and PSHTML.

Illustration of my project structure.

Our Objective

Now, the code is not really a big challenge because it’s PowerShell. We are familiar to use and explore it as per our requirement. With no theory let me jump over to PowerShell scripts!

Now, we made code refactoring in a simple way – Yes, we have one main page named (main.ps1) and 3 routes (about.ps1 , home.ps1  and contact.ps1). I really loved it! On other hand it took some time for me to understand the static route! I logged a bug in Polaris repo and received help from @tiberriver256 

Here comes the PSHTML Code




Enjoy PowerShell!

2 thoughts on “Organize your Polaris Code using PSHTML module

  1. Very cool blog chain you’ve got going here. We’ve thought about adding built-in support for a couple of PowerShell view engines like PSHTML and EPS.

    One suggestion, unless you want to share the source code for your routes you may want to remove the static route for your routes folder since you probably want the server to execute those scripts when /home or /about is requested from the browser. The static route would serve the ps1 file without being executed to anyone requesting it via /routes/home.ps1 which may not be that bad in this demo 🙂 but could be a risk if you thought the code was hidden.

  2. It will awesome to get PSHTML and EPS as view engines! Yes, only for demo I am exposing the code in routes! In parallel I will think alternate as per your suggestion. Thanks for your valuable feedback Micah!

Leave a Reply

Your email address will not be published. Required fields are marked *