Many of our micro apps will use the same static assets in order not to replicate these resources across apps. We can create a micro app that will serve all the shared resources.
Instead of having a main public
folder, each micro app that wants to serve static files can have a separate public
folder. This means that we can move all of our shared static resources, and move them to the inner public
folder.
We will have the following folder structure:
apps/ -- shared/ ---- public ------ assets/ ---- index.js
The index.js
file will have the following content:
'use strict'; const path = require('path'); const serveStatic = require('serve-static'); class Shared { constructor(config, core, app) { this.app = app; this.root = app.get('root'); this.rootUrl = '/'; this.serverStaticFiles(); } serverStaticFiles() { let folderPath = path.resolve(this.root, __dirname, './public'); this.app.use(this.rootUrl, serveStatic(folderPath)); } } module.exports = Shared...