简体   繁体   中英

Using webexpress and pug/jade to serve page with autodesk forge viewer

I am programming a node.js webexpress server that uses pug (jade) to create a website for viewing (revit) files uploaded to autodesk forge.

The webserver uses axios to communicate with forge and allows for logging in, creating and opening a bucket, uploading files and to get the URN for projects that were uploaded to the bucket.

When it comes to setting up the viewer I have examples that use viewerapp being set up locally in the browser. I am however using pug to create the pages and this does not seem to allow for keeping the page with the viewer alive in the browser and only updating it. Otherwise every mouseclick in the browser window would set up a new viewer, which seems both slow and overkill.

The socket library appears to allow for two way communication between webserver and browser but that's a whole new library to learn that I rather would not include if not necessary.

So the first question is if it is even possible to use node.js webexpress and pug to dynamically create a webpage with the forge viewer in it, and buttons that allow for changing views without resending the entire page including setting up the viewer again.

And if so, is there a simpler way to do so than relying on the socket library?

I can of course put all the viewer logic in a javascript file that gets loaded with the page, but I rather not do so if not necessary, as that would expose too much of the javascript and the connection to forge to the end user. I would prefer it if this can be kept on the webserver instead.

I have looked at https://learnforge.autodesk.io/#/viewer/2legged/nodejs and other sample code but this does not seem to answer my question in that the viewer seems to be created and maintained in the browser, not by the node.js webserver.

So the first question is if it is even possible to use node.js webexpress and pug to dynamically create a webpage with the forge viewer in it, and buttons that allow for changing views without resending the entire page including setting up the viewer again.

For sure. Viewer can be dynamically loaded and unloaded with native JavaScript. See a good read for details here and sample code here . So can the models - see an article here and sample here .

One pitfall you'd want to avoid is to never hide/detach the canvas without unloading the Viewer first. At the time of writing Viewer does not support rendering to a zero-sized canvas, yet.

And if so, is there a simpler way to do so than relying on the socket library?

Unfortunately Viewer does not support server-side rendering just yet, so we are not spoiled with options other than Websocket. And your concern is totally legit, see some great discussion here and here over the security of WebGL. There's no other rendering engine available for Viewer, and that should maintain unless certain other next-gen tech takes precedence over WebGL (do not see that coming in the foreseeable future though) or for certain WebAssembly library to take precedence over directly calling WebGL, which should take care of code obfuscation to certain extent.

However nothing should stop you from securing your code with proper AAA (Viewer supports API proxy and that should further harden your security measures), as well as these common obfuscation practices to protect your code from abuse.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM