Call Client Template Code from Server

Hi!

I’m using JsonRoutes with the intent of hitting the server with some params to generate an excel file.

My excel creation is working perfectly in a client side Template already. I tried exporting this function and then calling it in JsonRoutes but got the cannot find Template.html error. This makes sense because the server doesn’t have access to html. Is there any convenient away I can accomplish this. My workaround is to move the excel creation to the server. But I’d rather not do this because now I gotta change my client-side code to make an API call to the server’s JsonRoutes.

I’m not sure I fully understand your setup and middleware.

I feel like creating files is more secure and suited to the server. I personally would restrict that method to the server to begin with, but if you want to use it for both, you could probably export it in imports.

If you are relying on html in the template to generate the excel file, you can take the html and make a function that takes any template values being interpolated and returns what you currently have in your html as a multiline string in backticks.

My issue was with exporting the function using imports. I was able to resolve this by just wrapping the load of the html and other files in a Meteor.isClient