Hello everyone
@wildhart here (Chris) - I used to be fairly active here pretty much since the start of Meteor and for a good few years, but have been quiet recently. In the background I’ve still been busily maintaining my own Meteor-based SaaS product [1] and apps for private-clients, plus supporting my packages wildhart:jobs and wildhart:partitioner - both recently updated for Meteor 3.
One of those private clients requested that all the UI and front-end logic for their in-house app should be completely private to hide their company IP. The app does quite a bit of data manipulation and Word, Excel and PDF file generation in the frontend, so there is quite a bit of company IP in the front-end code.
While almost all of the UI is lazy-loaded per-route and component, the lazily loaded modules are served by the /__meteor__/dynamic-import/fetch endpoint without any authentication, and Meteor’s own dynamic-versions.js in the main bundle even lists the paths, so it’s fairly easy for a non-logged in user to identify and fetch ALL the front-end code. With AI tools it’s much easier these days for the AI to scrape this code, render the UI and copy the business logic.
Yes, you can move all this code server-side, but that shouldn’t be necessary. A complex, almost spreadsheet-like UI for managing multi-million dollar construction projects requires lots of instant validation and interactive UI built into the front end, and PDF/Word/Excel generation within the browser is much more responsive for the user and keeps blocking, synchronous code off the server. There should be a way to make this code private.
So I wrote a fairly simple package to require cookie auth on the /fetch endpoint: wildhart:dynamic-import-auth
A feature like this has been requested several times:
- Possibility to restrict dynamic imports based on authentication - 2018 Forum topic
- Hiding the names of files from dynamic imports - Meteor issue #11217
- Complete description of the available dynamic modules - Meteor issue #10767
There are some caveats for making this work - mainly the frontend should never try to fetch code while the user is logged out - but the package provides a front-end helper method to defer route modules and lazy components, e.g. in Vue:
lazy loaded route:
import { deferUntilLoggedIn} from 'meteor/wildhart:dynamic-import-auth';
routes = {
...
{
path: '/projects',
component: deferUntilLoggedIn(() => import('/imports/ui/Projects.vue')),
meta: {auth: true},
}
lazy loaded component, within the main non-lazy app bar:
components: {
SyncStatus: deferUntilLoggedIn(() => import('/imports/ui/SyncStatus.vue')),
}
I hope someone finds it useful! Any feedback welcome.