Answer the question
In order to leave comments, you need to log in
How to combine vue-server-renderer and vm2?
Hello, I need to do server rendering for vue.js, while I need to execute untrusted code from .vue components.
In order to be safe, I want to take out server rendering in sandbox vm2
But nothing comes out.
I'm trying to do something like this:
const fs = require('fs');
const express = require('express');
const { createBundleRenderer } = require('vue-server-renderer');
const {NodeVM} = require('vm2');
const app = express();
app.get('*', (req, res) => {
let bundleRenderer = createBundleRenderer(
require('./dist/vue-ssr-bundle.json'),
{
template: fs.readFileSync('./public/index.html', 'utf-8')
}
);
const vm = new NodeVM({
sandbox: {
bundleRenderer,
res,
req
},
require: {
external: true,
}
})
vm.run(`
bundleRenderer
.renderToStream({url: req.path})
.pipe(res);
`, 'server.js')
});
app.listen(8090);
[Vue warn]: Error in beforeCreate hook: "TypeError: 'defineProperty' on proxy: trap returned truish for adding property 'styles' that is incompatible with the existing property in the proxy target"
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question