@rpcbase/server 0.5.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin.js CHANGED
@@ -2,10 +2,11 @@
2
2
  /* @flow */
3
3
  const path = require("path")
4
4
  require("dotenv").config({path: path.join(__dirname, "./.env")})
5
+
5
6
  const yargs = require("yargs/yargs")
6
7
  const {hideBin} = require("yargs/helpers")
7
8
 
8
- const start_server = require("./start_server")
9
+ const start_server = require("./cli/start_server")
9
10
 
10
11
  let is_command = false
11
12
 
@@ -1,11 +1,37 @@
1
1
  /* @flow */
2
2
  const {execSync} = require("child_process")
3
+ const path = require("path")
4
+ const fs = require("fs")
5
+
6
+ const is_production = "yes" === process.env.INFRASTRUCTURE_IS_PRODUCTION
7
+
8
+ // TODO: auto create network if necessary
9
+ // docker network create local-network
3
10
 
4
11
  const start_server = async() => {
12
+ if (is_production) {
13
+ console.log("server will run in production")
14
+ }
15
+
16
+ const infrastructure_dir = path.join(process.cwd(), "../infrastructure")
17
+
18
+ // env
19
+ const env_path = path.relative(infrastructure_dir, path.join(process.cwd(), "./.env"))
20
+
21
+ // prefix
22
+ const proj_parent_dir = path.join(infrastructure_dir, "../../")
23
+ const proj_prefix = path.basename(proj_parent_dir)
24
+
25
+ // compose files
26
+ const compose_files = ["-f common.yml"]
27
+ if (is_production) compose_files.push("-f prod.yml")
28
+ else compose_files.push("-f dev.yml")
29
+
30
+ const cmd = `docker-compose --env-file ${env_path} -p ${proj_prefix} ${compose_files.join(" ")} up --build --remove-orphans`
5
31
 
6
- execSync("docker-compose --help", {stdio: "inherit"})
32
+ console.log("RUN", cmd)
33
+ execSync(cmd, {stdio: "inherit", cwd: infrastructure_dir})
7
34
 
8
- console.log("Done.")
9
35
  }
10
36
 
11
37
  module.exports = start_server
@@ -6,12 +6,10 @@ const glob = require("glob")
6
6
  const src_path = path.join(process.cwd(), "./src/")
7
7
  const build_dir = path.join(process.cwd(), "build/")
8
8
  const client_build_dir = path.join(build_dir, "./client")
9
- const index_file_buffer = fs.readFileSync(path.join(client_build_dir, "./index.html"))
10
9
 
11
10
 
12
11
  // TODO: add build time static assets compression
13
12
 
14
-
15
13
  const async_wrapper = fn => (req, res, next) => {
16
14
  Promise.resolve(fn(req, res, next))
17
15
  .catch(next)
@@ -32,6 +30,14 @@ const get_client_routes = () => {
32
30
  const client_router = (app) => {
33
31
  const client_routes = get_client_routes()
34
32
 
33
+ const index_file_path = path.join(client_build_dir, "./index.html")
34
+ if (!fs.existsSync(index_file_path)) {
35
+ console.log("index file not found, skipping server:client_router")
36
+ return
37
+ }
38
+
39
+ const index_file_buffer = fs.readFileSync(index_file_path)
40
+
35
41
  app.get("*", async_wrapper(async(req, res, next) => {
36
42
  const full_path = req.baseUrl + req.path
37
43
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.5.0",
3
+ "version": "0.9.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -11,6 +11,7 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "connect-redis": "6.0.0",
14
+ "dotenv": "10.0.0",
14
15
  "glob": "7.2.0",
15
16
  "redis": "3.1.2",
16
17
  "yargs": "17.3.0"