From 5cc0bb28b0ab978da9098fccdc0d5494821c8348 Mon Sep 17 00:00:00 2001 From: Joel Chen Date: Fri, 5 Feb 2021 00:48:38 -0800 Subject: [PATCH] update demo for create-app --- .../template/src/server/config.ts | 4 +-- .../template/src/server/index.ts | 3 +++ .../template/src/server/routes.ts | 25 ++++++++----------- samples/create-app-demo/src/server/config.ts | 4 +-- samples/create-app-demo/src/server/index.ts | 3 +++ samples/create-app-demo/src/server/routes.ts | 25 ++++++++----------- .../src/server/config.ts | 2 +- 7 files changed, 31 insertions(+), 35 deletions(-) diff --git a/packages/xarc-create-app/template/src/server/config.ts b/packages/xarc-create-app/template/src/server/config.ts index 5565736bb..3750f16f0 100644 --- a/packages/xarc-create-app/template/src/server/config.ts +++ b/packages/xarc-create-app/template/src/server/config.ts @@ -1,5 +1,3 @@ -"use strict"; - /** * A simple configuration to setup fastify to serve routes for the * Electrode X webapp. @@ -23,7 +21,7 @@ export const config = { */ "@xarc/app-dev": { priority: -1, - enable: process.env.WEBPACK_DEV === "true" + enable: Boolean(process.env.WEBPACK_DEV) } }, // don't start fastify server automatically so app can setup routes diff --git a/packages/xarc-create-app/template/src/server/index.ts b/packages/xarc-create-app/template/src/server/index.ts index bf0f9a03c..ab65b0f39 100644 --- a/packages/xarc-create-app/template/src/server/index.ts +++ b/packages/xarc-create-app/template/src/server/index.ts @@ -4,6 +4,7 @@ import { config } from "./config"; /** * main entry point for application + * * @returns fastify server instance */ export async function start() { @@ -15,6 +16,8 @@ export async function start() { const server = await fastifyServer(config); + // it's important that the routes setup is import *after* runtime support is loaded + // else isomorphic assets during development may not work properly const { setupRoutes } = await import("./routes"); setupRoutes(server); diff --git a/packages/xarc-create-app/template/src/server/routes.ts b/packages/xarc-create-app/template/src/server/routes.ts index c340a9427..38ef931e7 100644 --- a/packages/xarc-create-app/template/src/server/routes.ts +++ b/packages/xarc-create-app/template/src/server/routes.ts @@ -7,26 +7,23 @@ import { PageRenderer } from "@xarc/react"; * @returns nothing */ export function setupRoutes(server) { - let homeRenderer: PageRenderer; + const homeRenderer: PageRenderer = new PageRenderer({ + pageTitle: "xarc React App demo", + subApps: [ + { name: home.name, ssr: true }, + { name: Demo2.name, ssr: true }, + { name: Demo3.name, ssr: true } + ], + prodAssetData: { + cdnMap: "config/assets.json" + } + }); server.route({ method: "GET", path: "/", async handler(request, reply) { try { - if (!homeRenderer) { - homeRenderer = new PageRenderer({ - pageTitle: "xarc React App demo", - subApps: [ - { name: home.name, ssr: true }, - { name: Demo2.name, ssr: true }, - { name: Demo3.name, ssr: true } - ], - prodAssetData: { - cdnMap: "config/assets.json" - } - }); - } const context = await homeRenderer.render({ request }); reply.type("text/html"); diff --git a/samples/create-app-demo/src/server/config.ts b/samples/create-app-demo/src/server/config.ts index 5565736bb..3750f16f0 100644 --- a/samples/create-app-demo/src/server/config.ts +++ b/samples/create-app-demo/src/server/config.ts @@ -1,5 +1,3 @@ -"use strict"; - /** * A simple configuration to setup fastify to serve routes for the * Electrode X webapp. @@ -23,7 +21,7 @@ export const config = { */ "@xarc/app-dev": { priority: -1, - enable: process.env.WEBPACK_DEV === "true" + enable: Boolean(process.env.WEBPACK_DEV) } }, // don't start fastify server automatically so app can setup routes diff --git a/samples/create-app-demo/src/server/index.ts b/samples/create-app-demo/src/server/index.ts index bf0f9a03c..ab65b0f39 100644 --- a/samples/create-app-demo/src/server/index.ts +++ b/samples/create-app-demo/src/server/index.ts @@ -4,6 +4,7 @@ import { config } from "./config"; /** * main entry point for application + * * @returns fastify server instance */ export async function start() { @@ -15,6 +16,8 @@ export async function start() { const server = await fastifyServer(config); + // it's important that the routes setup is import *after* runtime support is loaded + // else isomorphic assets during development may not work properly const { setupRoutes } = await import("./routes"); setupRoutes(server); diff --git a/samples/create-app-demo/src/server/routes.ts b/samples/create-app-demo/src/server/routes.ts index c340a9427..38ef931e7 100644 --- a/samples/create-app-demo/src/server/routes.ts +++ b/samples/create-app-demo/src/server/routes.ts @@ -7,26 +7,23 @@ import { PageRenderer } from "@xarc/react"; * @returns nothing */ export function setupRoutes(server) { - let homeRenderer: PageRenderer; + const homeRenderer: PageRenderer = new PageRenderer({ + pageTitle: "xarc React App demo", + subApps: [ + { name: home.name, ssr: true }, + { name: Demo2.name, ssr: true }, + { name: Demo3.name, ssr: true } + ], + prodAssetData: { + cdnMap: "config/assets.json" + } + }); server.route({ method: "GET", path: "/", async handler(request, reply) { try { - if (!homeRenderer) { - homeRenderer = new PageRenderer({ - pageTitle: "xarc React App demo", - subApps: [ - { name: home.name, ssr: true }, - { name: Demo2.name, ssr: true }, - { name: Demo3.name, ssr: true } - ], - prodAssetData: { - cdnMap: "config/assets.json" - } - }); - } const context = await homeRenderer.render({ request }); reply.type("text/html"); diff --git a/samples/subapp2-react-query-todoapp/src/server/config.ts b/samples/subapp2-react-query-todoapp/src/server/config.ts index 5c1d6618f..94eb17974 100644 --- a/samples/subapp2-react-query-todoapp/src/server/config.ts +++ b/samples/subapp2-react-query-todoapp/src/server/config.ts @@ -23,7 +23,7 @@ export const config = { */ "@xarc/app-dev": { priority: -1, - enable: process.env.WEBPACK_DEV === "true" + enable: Boolean(process.env.WEBPACK_DEV) } }, deferStart: true