Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
server.get('/', async (req, res) => {
const { App, props } = createApp();
// URLSync
const searchState = {
query: 'iPhone',
refinementList: {
brand: ['Apple'],
},
};
const resultsState = await findResultsState(App, {
...props,
searchState,
});
const initialState = {
resultsState,
searchState,
};
const body = ReactDOM.renderToString();
res.send(
template({
title: 'Hello World from the server',
initialState: JSON.stringify(initialState),
body,
static async getInitialProps({ asPath }) {
const searchState = pathToSearchState(asPath);
const resultsState = await findResultsState(App, {
...DEFAULT_PROPS,
searchState,
});
return {
resultsState,
searchState,
};
}
server.get('/', async (_, res) => {
const { App, props } = createApp();
const searchState = {
query: 'iPhone',
page: 5,
refinementList: {
brand: ['Apple'],
},
};
const resultsState = await findResultsState(App, {
...props,
searchState,
});
const initialState = {
searchState,
resultsState,
};
const plainHTML = renderToString();
res.send(
template({
body: plainHTML,
title: 'Hello World from the server',
initialState: JSON.stringify(initialState),