fastify / point-of-view

Template rendering plugin for Fastify
MIT License
338 stars 86 forks source link

how to use same identifier for different directory paths in ejs with different static assest folder #334

Closed matt212 closed 2 years ago

matt212 commented 2 years ago

Prerequisites

Issue

this is my ejs

<head>

     <%- include('../../public/components/headercontent.html'); %>

</head>

and below is my app/server.js file configuration

fastify.register(require("point-of-view"), {
  engine: {
    ejs: require("ejs"),
  },
  root: path.join(__dirname, "../views"),
});

fastify.register(require("fastify-static"), {
  root: path.join(__dirname, "../") + "/public/",
});

so the above works as expected my problem statement is below i have two static assets folder

what is expected scenario is

I want to use same public name but path can be different something like
case scenario 1

fastify.register(require("fastify-static"), {
  root: path.join(__dirname, "../") + "/**public-release**/",
  nameused:'public'
});

case scenario 2

fastify.register(require("fastify-static"), {
  root: path.join(__dirname, "../") + "/**public**/",
  nameused:'public'
});

is there a way I can achieve this ?

Objective :

1.i want to switch dynamically my js and css for home grown release /bundling system and without touching my existing codebase of linking them

2.so the idea here is to just the update the point where static assests are served and change them through custom yarn or npm run scripts

  1. for eg:- when i passed say dev the static assets should serve from 'public ' folder

    and when i passed say prod the static assets should serve from 'public-release' folder

matt212 commented 2 years ago

So , there is middle ground approach which I implemented for my boilerplate

Github Repo: Node.js Postgresql fastify

TLDR;

nodejs-web-app-Env-pt1 nodejs-web-app-Env-pt2

how-to-release-node-app