feat: fix server

This commit is contained in:
cudr 2019-10-27 23:50:01 +03:00
parent 20f3c3234c
commit afaff1f80a
3 changed files with 19 additions and 4 deletions

View File

@ -14,6 +14,8 @@
"@types/react-dom": "16.9.0", "@types/react-dom": "16.9.0",
"@types/slate-react": "^0.22.5", "@types/slate-react": "^0.22.5",
"concurrently": "^4.1.2", "concurrently": "^4.1.2",
"cross-env": "^6.0.3",
"express": "^4.17.1",
"faker": "^4.1.0", "faker": "^4.1.0",
"lodash": "^4.17.15", "lodash": "^4.17.15",
"nodemon": "^1.19.2", "nodemon": "^1.19.2",
@ -28,7 +30,7 @@
"scripts": { "scripts": {
"start": "node server.js", "start": "node server.js",
"start:cra": "react-scripts start", "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\"", "dev": "concurrently \"yarn start:cra\" \"yarn serve\"",
"serve": "nodemon --watch ../backend/lib --inspect server.js" "serve": "nodemon --watch ../backend/lib --inspect server.js"
}, },

View File

@ -1,6 +1,12 @@
const Connection = require('@slate-collaborative/backend') const Connection = require('@slate-collaborative/backend')
const defaultValue = require('./src/defaultValue') 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 = { const config = {
entry: server, // or specify port to start io server entry: server, // or specify port to start io server
@ -21,4 +27,6 @@ const config = {
const connection = new Connection(config) const connection = new Connection(config)
server.listen(9000) app.use(express.static('build'))
server.listen(PORT)

View File

@ -35,8 +35,13 @@ class Client extends Component<ClienProps> {
alpha: 1 alpha: 1
}) })
const origin =
process.env.NODE_ENV === 'production'
? window.location.origin
: 'http://localhost:9000'
const options = { const options = {
url: `http://localhost:9000/${this.props.slug}`, url: `${origin}/${this.props.slug}`,
connectOpts: { connectOpts: {
query: { query: {
name: this.props.name, name: this.props.name,