From afaff1f80acef128b846ad3fd5b42a7e69b507cc Mon Sep 17 00:00:00 2001 From: cudr Date: Sun, 27 Oct 2019 23:50:01 +0300 Subject: [PATCH] feat: fix server --- packages/example/package.json | 4 +++- packages/example/server.js | 12 ++++++++++-- packages/example/src/Client.tsx | 7 ++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/example/package.json b/packages/example/package.json index e38d25c..460a1eb 100644 --- a/packages/example/package.json +++ b/packages/example/package.json @@ -14,6 +14,8 @@ "@types/react-dom": "16.9.0", "@types/slate-react": "^0.22.5", "concurrently": "^4.1.2", + "cross-env": "^6.0.3", + "express": "^4.17.1", "faker": "^4.1.0", "lodash": "^4.17.15", "nodemon": "^1.19.2", @@ -28,7 +30,7 @@ "scripts": { "start": "node server.js", "start:cra": "react-scripts start", - "build": "react-scripts build", + "build": "cross-env NODE_ENV=production && react-scripts build", "dev": "concurrently \"yarn start:cra\" \"yarn serve\"", "serve": "nodemon --watch ../backend/lib --inspect server.js" }, diff --git a/packages/example/server.js b/packages/example/server.js index 087bda0..f579cff 100644 --- a/packages/example/server.js +++ b/packages/example/server.js @@ -1,6 +1,12 @@ const Connection = require('@slate-collaborative/backend') const defaultValue = require('./src/defaultValue') -const server = require('http').createServer() +const express = require('express') + +const app = express() + +const server = require('http').createServer(app) + +const PORT = process.env.PORT || 9000 const config = { entry: server, // or specify port to start io server @@ -21,4 +27,6 @@ const config = { const connection = new Connection(config) -server.listen(9000) +app.use(express.static('build')) + +server.listen(PORT) diff --git a/packages/example/src/Client.tsx b/packages/example/src/Client.tsx index 21eaea2..6474476 100644 --- a/packages/example/src/Client.tsx +++ b/packages/example/src/Client.tsx @@ -35,8 +35,13 @@ class Client extends Component { alpha: 1 }) + const origin = + process.env.NODE_ENV === 'production' + ? window.location.origin + : 'http://localhost:9000' + const options = { - url: `http://localhost:9000/${this.props.slug}`, + url: `${origin}/${this.props.slug}`, connectOpts: { query: { name: this.props.name,