Skip to content

Commit

Permalink
update sample poc-subapp-min to fastify
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip committed Jul 21, 2020
1 parent 3ea2fe7 commit 572d831
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 108 deletions.
8 changes: 4 additions & 4 deletions samples/poc-subapp-min/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use strict";
module.exports = {
extends: "@xarc/app-dev/config/babel/babelrc.js"
};

module.exports = {
extends: "@xarc/app-dev/config/babel/babelrc.js"
};
14 changes: 3 additions & 11 deletions samples/poc-subapp-min/config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,8 @@ module.exports = {
"subapp-server": { options: { insertTokenIds: true } }
},
connections: {
default: {
host: process.env.HOST,
address: process.env.HOST_IP || "0.0.0.0",
port: portFromEnv(),
routes: {
cors: false
},
state: {
ignoreErrors: true
}
}
host: process.env.HOST,
address: process.env.HOST_IP || "0.0.0.0",
port: portFromEnv()
}
};
1 change: 1 addition & 0 deletions samples/poc-subapp-min/config/development.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
9 changes: 0 additions & 9 deletions samples/poc-subapp-min/config/development.json

This file was deleted.

24 changes: 1 addition & 23 deletions samples/poc-subapp-min/config/production.js
Original file line number Diff line number Diff line change
@@ -1,23 +1 @@
//
// This file is here to allow enabling the plugins inert and electrodeStaticPaths, overriding the
// settings in production.json, in order to serve the static JS and CSS bundle files from
// the dist directory so you can test your app server locally in production mode.
//
// When running in a real production environment where your static files are most likely served
// by a dedicated CDN server, you might want to turn these plugins off.
//

const serveStaticFiles = () => {
return process.env.STATIC_FILES_OFF !== "true";
};

module.exports = {
"plugins": {
"inert": {
"enable": serveStaticFiles()
},
"electrodeStaticPaths": {
"enable": serveStaticFiles()
}
}
};
module.exports = {};
9 changes: 0 additions & 9 deletions samples/poc-subapp-min/config/production.json

This file was deleted.

15 changes: 5 additions & 10 deletions samples/poc-subapp-min/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,13 @@
"build": "clap build"
},
"dependencies": {
"@hapi/inert": "^5.2.2",
"electrode-archetype-opt-react": "^2.0.4",
"@xarc/app": "^7.0.0",
"@xarc/fastify-server": "^2.0.0",
"electrode-confippet": "^1.5.0",
"electrode-server": "^3.0.0",
"electrode-static-paths": "^3.0.0",
"http-codes": "^1.0.0",
"react-router-dom": "^5.1.0",
"react-router": "^5.1.0",
"subapp-server": "../../packages/subapp-server",
"subapp-util": "../../packages/subapp-util",
"subapp-react": "../../packages/subapp-react"
"react": "^16.13.1",
"react-dom": "^16.13.1",
"subapp-react": "../../packages/subapp-react",
"subapp-server": "../../packages/subapp-server"
},
"devDependencies": {
"@xarc/app-dev": "^7.0.0"
Expand Down
3 changes: 0 additions & 3 deletions samples/poc-subapp-min/src/.babelrc.js

This file was deleted.

3 changes: 0 additions & 3 deletions samples/poc-subapp-min/src/server/.babelrc.js

This file was deleted.

39 changes: 3 additions & 36 deletions samples/poc-subapp-min/src/server/index.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,14 @@
"use strict";

/* eslint-disable global-require */

process.on("SIGINT", () => {
process.exit(0);
});

const electrodeConfippet = require("electrode-confippet");
const support = require("@xarc/app/support");

//
const electrodeServer = require("@xarc/fastify-server");

//
// sample to show electrode server startup events
// https://github.com/electrode-io/electrode-server#listener-function
//
function setupElectrodeServerEvents(emitter) {
emitter.on("config-composed", (data, next) => next());
emitter.on("server-created", (data, next) => next());
emitter.on("connection-set", (data, next) => next());
emitter.on("plugins-sorted", (data, next) => next());
emitter.on("plugins-registered", (data, next) => next());
emitter.on("server-started", (data, next) => next());
emitter.on("complete", (data, next) => next());
}

const startServer = config => {
if (!config.listener) config.listener = setupElectrodeServerEvents;
return electrodeServer(config, []);
module.exports = async () => {
await support.load();
await electrodeServer(electrodeConfippet.config);
};

//

module.exports = () =>
support.load().then(() => {
const config = electrodeConfippet.config;
return startServer(config).catch(e => {
console.log("start server failed -", e.message); // eslint-disable-line
process.exit(1);
});
});

if (require.main === module) {
module.exports();
}

0 comments on commit 572d831

Please sign in to comment.