Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
process.env.VUE_ENV = 'server'
const fs = require('fs')
const path = require('path')
const filePath = path.join(__dirname, '../wwwroot/dist/main-server.js')
const code = fs.readFileSync(filePath, 'utf8')
const vue_renderer = require('vue-server-renderer').createBundleRenderer(code)
//prevent XSS attack when initialize state
var serialize = require('serialize-javascript')
var prerendering = require('aspnet-prerendering')
module.exports = prerendering.createServerRenderer(function (params) {
return new Promise(
function (resolve, reject) {
// console.log('#prerendering#',params)
const context = {
url: params.url,
absoluteUrl: params.absoluteUrl,
baseUrl: params.baseUrl,
data: params.data,
domainTasks: params.domainTasks,
location: params.location,
origin: params.origin,
xss: serialize("")
}
const serverVueAppHtml = vue_renderer.renderToString(context, (err, _html) => {
if(err) { reject(err.message) }
resolve({
export function bootstrapServer(ngModule: Type<{}> | NgModuleFactory<{}>) {
enableProdMode();
let renderer = createServerRenderer(params => {
// Platform-server provider configuration
const setupOptions: IEngineOptions = {
appSelector: '',
ngModule: ngModule,
request: params,
providers: [
// Optional - Any other Server providers you want to pass (remember you'll have to provide them for the Browser as well)
{ provide: ssrDataToken, useValue: params.data },
{ provide: LOCATION, useValue: params.location }
]
};
return ngAspnetCoreEngine(setupOptions);
});
return renderer;
var createServerRenderer = require('aspnet-prerendering').createServerRenderer;
module.exports = createServerRenderer(function(params) {
return new Promise(function (resolve, reject) {
var message = 'The HTML was returned by the prerendering boot function. '
+ 'The boot function received the following params:'
+ '<pre>' + JSON.stringify(params, null, 4) + '</pre>';
resolve({
html: '<h3>Hello, world!</h3>' + message,
globals: { sampleData: { nodeVersion: process.version } }
});
});
});
var prerendering = require('aspnet-prerendering');
module.exports = prerendering.createServerRenderer(function (params) {
return new Promise(function (resolve, reject) {
var result = '<h1>Loading...</h1>'
+ '<p>Current time in Node is: ' + new Date() + '</p>'
+ '<p>Request path is: ' + params.location.path + '</p>'
+ '<p>Absolute URL is: ' + params.absoluteUrl + '</p>';
resolve({ html: result });
});
});
var prerendering = require('aspnet-prerendering');
module.exports = prerendering.createServerRenderer(function (params) {
return new Promise(function (resolve, reject) {
var result = '<h1>Loading...</h1>' +
'<p>Current time in Node is: ' + new Date() + '</p>' +
'<p>Request path is: ' + params.location.path + '</p>' +
'<p>Absolute URL is: ' + params.absoluteUrl + '</p>';
resolve({ html: result })
})
});