Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default async(ctx, next) => {
const context = {};
const content = renderToString(
{routes}
);
// This will contain the URL to redirect to if was used
if (context.url) {
return ctx.redirect(context.url);
}
ctx.type = 'text/html';
ctx.body = '\n' + content;
await next();
};
var data = {
name: 'joe_sky',
id: 100,
test0: true,
list: [{ no: 1, b: 1 }, { no: 2, b: 0 }, { no: 3, b: 1 }],
styles: { color: 'blue', fontSize: '15px' },
//testcom: TestComponent
};
//nj.registerComponent('TestComponent', TestComponent);
var templateT = nj.compileTagComponent(window.document.querySelector('div'), 'testT1');
//console.log(JSON.stringify(nj.templates['testT1']));
//console.log(templateT(data));
var html = InfernoServer.renderToString(templateT(data));
console.log(html);
expect(html).toBeTruthy();
done();
}
);
export default ({ dataFileName = `data.json`, scriptFileName, mode }) => {
let scriptSrc;
let styleTag = ``;
if (mode === `production`) {
scriptSrc = scriptFileName;
const stylesPath = path.resolve(__dirname, `../../public/styles.css`);
const styles = fs.readFileSync(stylesPath, `utf8`);
styleTag = `<style>${styles}</style>`;
} else {
scriptSrc = `http://localhost:8081/${WEBPACK_BUNDLE}`;
}
const appHtml = renderToString();
return `
<title>Know it all</title>
${styleTag}
app.get('/', (req, res) => {
const renderer = createRenderer()
const indexHTML = fs.readFileSync(`${__dirname}/index.html`).toString()
const appHtml = renderToString(
)
const appCSS = renderToMarkup(renderer)
res.write(
indexHTML
.replace('', appHtml)
.replace('', appCSS)
)
res.end()
})
module.exports = function infernoRender(App, searchResultsData) {
return InfernoServer.renderToString(
);
};
module.exports = (req, res) => {
res.type('text/html').code(200);
res.send(
renderToString(render())
);
};
function render(pathname, Markup, App, props) {
const styletron = new StyletronServer();
const appContent = InfernoServer.renderToString(createElement(App, {pathname, styletron}));
const styletronSheets = styletron.getStylesheets();
const markupProps = Object.assign({}, props, {appContent, styletronSheets});
return '' + InfernoServer.renderToStaticMarkup(createElement(Markup, markupProps));
}
.add(`Inferno(${infernoPkg.version})#renderToString`, function() {
InfernoServer.renderToString(infernoCreateElement.createElement(InfernoApp, data));
})
.add(`Preact(${preactPkg.version})#renderToString`, function() {
.get('/*', (req, res) => {
const markup = InfernoServer.renderToString();
res.status(200).send(
`
<title>Welcome to Razzle</title>
${assets.client.css
? ``
: ''}
${process.env.NODE_ENV === 'production'
? ``
: ``}
function html(ctx, renderProps, reducer, clientScript): string {
initServerI18n(ctx);
initServerConsent(ctx);
const state = ctx.getState();
const jsonGlobals = JsonGlobals({state});
initAssetURL(state.base.siteURL, state.base.routePrefix, state.base.manifest);
const store = configureStore(state, reducer);
const styletron = new StyletronServer({prefix: '_'});
const reactMarkup = renderToString(
);
return rootHtml({styletron, jsonGlobals, reactMarkup, clientScript, nonce: ctx.state.nonce});
}