Skip to content

Commit

Permalink
update demo for create-app
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip committed Feb 5, 2021
1 parent 3dab9cd commit 5cc0bb2
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 35 deletions.
4 changes: 1 addition & 3 deletions packages/xarc-create-app/template/src/server/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict";

/**
* A simple configuration to setup fastify to serve routes for the
* Electrode X webapp.
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions packages/xarc-create-app/template/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { config } from "./config";

/**
* main entry point for application
*
* @returns fastify server instance
*/
export async function start() {
Expand All @@ -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);

Expand Down
25 changes: 11 additions & 14 deletions packages/xarc-create-app/template/src/server/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
4 changes: 1 addition & 3 deletions samples/create-app-demo/src/server/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict";

/**
* A simple configuration to setup fastify to serve routes for the
* Electrode X webapp.
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions samples/create-app-demo/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { config } from "./config";

/**
* main entry point for application
*
* @returns fastify server instance
*/
export async function start() {
Expand All @@ -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);

Expand Down
25 changes: 11 additions & 14 deletions samples/create-app-demo/src/server/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion samples/subapp2-react-query-todoapp/src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5cc0bb2

Please sign in to comment.