Skip to content

Commit

Permalink
update create-app demo to fastify-server ver 3 (#1828)
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip authored Feb 18, 2021
1 parent 7ce85aa commit da468b7
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 43 deletions.
2 changes: 1 addition & 1 deletion packages/xarc-create-app/template/_package.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = (base, merge) => {
dependencies: {
"@babel/runtime": "^7.12.5",
"@xarc/app": "^8.2.0", // version will come from ../package.json
"@xarc/fastify-server": "^2.0.0",
"@xarc/fastify-server": "^3.2.2",
"@xarc/react": "^0.1.0", // version will come from ../package.json
"@xarc/react-query": "^0.1.1", // version will come from ../package.json
"@xarc/react-redux": "^0.1.0" // version will come from ../package.json
Expand Down
1 change: 1 addition & 0 deletions packages/xarc-create-app/template/src/demo3/copyright.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const copyRightMessage = ${new Date().getFullYear()} Your (Company) name here`;
3 changes: 2 additions & 1 deletion packages/xarc-create-app/template/src/demo3/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { React, ReactSubApp } from "@xarc/react";
import { reactQueryFeature, useQuery } from "@xarc/react-query";
import { demo3QueryFn } from "./react-query-fetch";
import { copyRightMessage } from "./copyright";

const Demo3 = () => {
const { data } = useQuery("demo3", demo3QueryFn, { staleTime: 2000 });
Expand All @@ -27,7 +28,7 @@ const Demo3 = () => {
<h2>subapp demo3 with react-query</h2>
data: <pre>{JSON.stringify(data)}</pre>
</div>
<p style={{ textAlign: "center" }}>© {new Date().getFullYear()} Your (Company) name here</p>
<p style={{ textAlign: "center" }}>{copyRightMessage}</p>
</div>
);
};
Expand Down
51 changes: 34 additions & 17 deletions packages/xarc-create-app/template/src/server/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
import {
ConnectionConfig,
PluginsConfig,
PluginOptions,
ElectrodeServerConfig
} from "@xarc/fastify-server/lib/types";

//
// specify connection info for fastify server
//
const connection: ConnectionConfig = {
host: process.env.HOST || "localhost",
// The env APP_SERVER_PORT allows Electrode X to control app's listening port during dev
// to serve both static assets and app under a unified proxy port
port: parseInt(process.env.APP_SERVER_PORT || process.env.PORT || "3000")
};

//
// specify plugins to register with fastify server
//
const plugins: PluginsConfig = {
/**
* Register the dev support plugin
*/
"@xarc/app-dev": {
priority: -1,
enable: Boolean(process.env.WEBPACK_DEV)
}
};

/**
* A simple configuration to setup fastify to serve routes for the
* Electrode X webapp.
Expand All @@ -8,22 +38,9 @@
* 2. https://www.npmjs.com/package/config
*
*/
export const config = {
connection: {
host: process.env.HOST || "localhost",
// The env APP_SERVER_PORT allows Electrode X to control app's listening port during dev
// to serve both static assets and app under a unified proxy port
port: parseInt(process.env.APP_SERVER_PORT || process.env.PORT || "3000")
},
plugins: {
/**
* Register the dev support plugin
*/
"@xarc/app-dev": {
priority: -1,
enable: Boolean(process.env.WEBPACK_DEV)
}
},
export const config: ElectrodeServerConfig = {
// don't start fastify server automatically so app can setup routes
deferStart: true
deferStart: true,
connection,
plugins
};
12 changes: 6 additions & 6 deletions samples/create-app-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
},
"dependencies": {
"@babel/runtime": "^7.12.5",
"@xarc/app": "^9.0.1",
"@xarc/fastify-server": "^2.0.0",
"@xarc/react": "^0.1.6",
"@xarc/react-query": "^0.1.2",
"@xarc/react-redux": "^0.1.5"
"@xarc/app": "^9.0.2",
"@xarc/fastify-server": "^3.2.2",
"@xarc/react": "^0.1.7",
"@xarc/react-query": "^0.1.3",
"@xarc/react-redux": "^0.1.6"
},
"devDependencies": {
"@types/node": "^14.14.6",
"@xarc/app-dev": "^9.0.1",
"@xarc/app-dev": "^9.0.2",
"ts-node": "^9.0.0",
"typescript": "^4.0.3"
}
Expand Down
1 change: 1 addition & 0 deletions samples/create-app-demo/src/demo3/copyright.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const copyRightMessage = ${new Date().getFullYear()} Your (Company) name here`;
3 changes: 2 additions & 1 deletion samples/create-app-demo/src/demo3/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { React, ReactSubApp } from "@xarc/react";
import { reactQueryFeature, useQuery } from "@xarc/react-query";
import { demo3QueryFn } from "./react-query-fetch";
import { copyRightMessage } from "./copyright";

const Demo3 = () => {
const { data } = useQuery("demo3", demo3QueryFn, { staleTime: 2000 });
Expand All @@ -27,7 +28,7 @@ const Demo3 = () => {
<h2>subapp demo3 with react-query</h2>
data: <pre>{JSON.stringify(data)}</pre>
</div>
<p style={{ textAlign: "center" }}>© {new Date().getFullYear()} Your (Company) name here</p>
<p style={{ textAlign: "center" }}>{copyRightMessage}</p>
</div>
);
};
Expand Down
51 changes: 34 additions & 17 deletions samples/create-app-demo/src/server/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
import {
ConnectionConfig,
PluginsConfig,
PluginOptions,
ElectrodeServerConfig
} from "@xarc/fastify-server/lib/types";

//
// specify connection info for fastify server
//
const connection: ConnectionConfig = {
host: process.env.HOST || "localhost",
// The env APP_SERVER_PORT allows Electrode X to control app's listening port during dev
// to serve both static assets and app under a unified proxy port
port: parseInt(process.env.APP_SERVER_PORT || process.env.PORT || "3000")
};

//
// specify plugins to register with fastify server
//
const plugins: PluginsConfig = {
/**
* Register the dev support plugin
*/
"@xarc/app-dev": {
priority: -1,
enable: Boolean(process.env.WEBPACK_DEV)
}
};

/**
* A simple configuration to setup fastify to serve routes for the
* Electrode X webapp.
Expand All @@ -8,22 +38,9 @@
* 2. https://www.npmjs.com/package/config
*
*/
export const config = {
connection: {
host: process.env.HOST || "localhost",
// The env APP_SERVER_PORT allows Electrode X to control app's listening port during dev
// to serve both static assets and app under a unified proxy port
port: parseInt(process.env.APP_SERVER_PORT || process.env.PORT || "3000")
},
plugins: {
/**
* Register the dev support plugin
*/
"@xarc/app-dev": {
priority: -1,
enable: Boolean(process.env.WEBPACK_DEV)
}
},
export const config: ElectrodeServerConfig = {
// don't start fastify server automatically so app can setup routes
deferStart: true
deferStart: true,
connection,
plugins
};

0 comments on commit da468b7

Please sign in to comment.