Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(async () => {
const BrowserRouter = await createInitialBrowserRouter({
routeConfig,
render: createRender({
renderError: (
{ error }, // eslint-disable-line react/prop-types
) => <div>{error.status === 404 ? 'Not found' : 'Error'}</div>,
}),
});
hydrate(, document.getElementById('reactDiv'));
})();
export async function mountClient(routeConfig) {
const environment = createRelayEnvironment(
JSON.parse(window.__RELAY_BOOTSTRAP__)
) // eslint-disable-line
const historyMiddlewares = [queryMiddleware]
const resolver = new Resolver(environment)
const render = createRender({})
try {
const Router = await createInitialFarceRouter({
historyProtocol: new BrowserProtocol(),
historyMiddlewares,
routeConfig,
resolver,
render,
})
Loadable.preloadReady().then(() => {
ReactDOM.hydrate(
app.use(async (req, res) => {
const {status, element} = await getFarceResult({
url: req.url,
routeConfig,
render: createRender({
renderError: (
{ error }, // eslint-disable-line react/prop-types
) => <div>{error.status === 404 ? 'Not found' : 'Error'}</div>,
}),
});
const htmlString = `
<title>Relay Modern SSR</title>
<div id="reactDiv">${renderToString(element)}</div>
import { Environment, Network, RecordSource, Store } from 'relay-runtime'
import { setEnviroment } from 'relay-compose'
import { ClientFetcher } from '../fetcher'
export function createResolver(fetcher) {
const environment = new Environment({
network: Network.create((...args) => fetcher.fetch(...args)),
store: new Store(new RecordSource()),
})
setEnviroment(environment)
return new Resolver(environment)
}
export const render = createRender({})
export function createClientResolver() {
// eslint-disable-next-line no-underscore-dangle, no-undef
const fetcher = new ClientFetcher(process.env.GRAPHQL_ENDPOINT, window.__RELAY_PAYLOADS__)
return createResolver(fetcher)
}
export function createClientRouter() {
return createConnectedRouter({ render })
}
/>
import(/* webpackChunkName: "page" */ './Page'))}
query={PageQuery}
render={renderProp}
/>
import(/* webpackChunkName: "home" */ './Home'))}
query={HomeQuery}
render={renderProp}
/>
);
export const render = createRender({});
import React, {Component} from 'react'
import BrowserProtocol from 'farce/lib/BrowserProtocol'
import queryMiddleware from 'farce/lib/queryMiddleware'
import createFarceRouter from 'found/lib/createFarceRouter'
import createRender from 'found/lib/createRender'
import {Resolver} from 'found-relay'
import Routes from './Routes'
import environment from './Environment'
const FarceRouter = createFarceRouter({
historyProtocol: new BrowserProtocol(),
historyMiddlewares: [queryMiddleware],
routeConfig: Routes,
render: createRender({}),
})
export default class Router extends Component {
render() {
return(
)
}
}
export function mountServer(routeConfig) {
const app = express.Router()
const fetcher = new ServerFetcher(process.env.METAPHYSICS_BASE_URL)
const resolver = createResolver(fetcher)
const render = createRender({})
app.get('/*', serverSideRender)
async function serverSideRender(req, res, next) {
try {
const { redirect, status, element } = await getFarceResult({
url: req.url,
historyMiddlewares: [queryMiddleware],
routeConfig,
resolver,
render,
})
if (redirect) {
res.redirect(302, redirect.url)
return
export async function mountClient(routeConfig) {
const fetcher = new ClientFetcher(
process.env.METAPHYSICS_BASE_URL,
window.__RELAY_PAYLOADS__
)
const resolver = createResolver(fetcher)
const render = createRender({})
const Router = await createInitialFarceRouter({
historyProtocol: new BrowserProtocol(),
historyMiddlewares: [queryMiddleware],
routeConfig,
resolver,
render,
})
ReactDOM.hydrate(
,
document.getElementById('root')
)
}