Prechádzať zdrojové kódy

Add env file for dev

Johan Le Baut 4 rokov pred
rodič
commit
0cd48de1c7
2 zmenil súbory, kde vykonal 34 pridanie a 16 odobranie
  1. 13 0
      .env.development
  2. 21 16
      src/common/socket-service.js

+ 13 - 0
.env.development

@@ -0,0 +1,13 @@
+BROWSER=firefox
+BABEL_ENV=debug
+NODE_ENV=development
+
+VUE_APP_SERVER_CONN=http
+VUE_APP_SERVER_HOST="localhost"
+VUE_APP_SERVER_PORT=2610
+
+DB=""
+DB_PORT=
+DB_NAME=""
+DB_USER=""
+DB_PASS=""

+ 21 - 16
src/common/socket-service.js

@@ -1,15 +1,20 @@
 'use strict';
 import io from 'socket.io-client';
 /* eslint-disable no-console */
-const SERVER_URL = 'https://' + process.env.VUE_APP_SERVER_HOST;
+
+const SERVER_URL = process.env.VUE_APP_SERVER_CONN + '://' + process.env.VUE_APP_SERVER_HOST;
 const SERVER_PORT = process.env.VUE_APP_SERVER_PORT;
 
 export default function SocketService(socketEventBus, vuexStore) {
   let store = vuexStore;
   let ioClient = null;
-  let connect = function(name) {
+  let connect = function (name) {
     let promise = new Promise((resolve, reject) => {
-      ioClient = io(SERVER_URL, {
+      let serverUrl = SERVER_URL;
+      if (SERVER_PORT != "") {
+        serverUrl += ':' + SERVER_PORT;
+      }
+      ioClient = io(serverUrl, {
         reconnectionAttempts: 2
       });
 
@@ -22,7 +27,7 @@ export default function SocketService(socketEventBus, vuexStore) {
 
       ioClient.on('connect', () => {
         console.log('Connected to server');
-        ioClient.emit('auth', name, function(response) {
+        ioClient.emit('auth', name, function (response) {
           if (response.res === 'ok') {
             resolve(response.message);
           } else {
@@ -56,7 +61,7 @@ export default function SocketService(socketEventBus, vuexStore) {
     return promise;
   };
 
-  let checkConnection = function(playername) {
+  let checkConnection = function (playername) {
     if (ioClient && ioClient.connected === false) {
       return connect(playername);
     } else {
@@ -64,15 +69,15 @@ export default function SocketService(socketEventBus, vuexStore) {
     }
   };
 
-  let disconnect = function() {
+  let disconnect = function () {
     console.log('Manual client disconnect');
     ioClient.close();
   };
-  let getGamesList = function(playername) {
+  let getGamesList = function (playername) {
     return checkConnection(playername).then(
       () => {
         return new Promise((resolve, reject) => {
-          ioClient.emit('games-list', playername, function(response) {
+          ioClient.emit('games-list', playername, function (response) {
             if (response.res === 'ok') {
               resolve(response.message);
             } else {
@@ -85,11 +90,11 @@ export default function SocketService(socketEventBus, vuexStore) {
     );
   };
 
-  let createGame = function(game) {
+  let createGame = function (game) {
     return checkConnection(game.player1).then(
       () => {
         return new Promise((resolve, reject) => {
-          ioClient.emit('create-game', game, function(response) {
+          ioClient.emit('create-game', game, function (response) {
             if (response.res === 'ok') {
               resolve(response.message);
             } else {
@@ -101,11 +106,11 @@ export default function SocketService(socketEventBus, vuexStore) {
       error => Promise.reject(error)
     );
   };
-  let joinGame = function(username, gameId, joinCreatedGame) {
+  let joinGame = function (username, gameId, joinCreatedGame) {
     return checkConnection(username).then(
       () => {
         return new Promise((resolve, reject) => {
-          ioClient.emit('join-game', { id: gameId, joinCreatedGame }, function(
+          ioClient.emit('join-game', { id: gameId, joinCreatedGame }, function (
             response
           ) {
             if (response.res === 'ok') {
@@ -119,11 +124,11 @@ export default function SocketService(socketEventBus, vuexStore) {
       error => Promise.reject(error)
     );
   };
-  let leaveGame = function(username) {
+  let leaveGame = function (username) {
     return checkConnection(username).then(
       () => {
         return new Promise(resolve => {
-          ioClient.emit('leave-game', username, function(response) {
+          ioClient.emit('leave-game', username, function (response) {
             resolve(response);
           });
         });
@@ -131,7 +136,7 @@ export default function SocketService(socketEventBus, vuexStore) {
       error => Promise.reject(error)
     );
   };
-  let endTurn = function(payload) {
+  let endTurn = function (payload) {
     return checkConnection(payload.username).then(
       () => {
         return new Promise(resolve => {
@@ -143,7 +148,7 @@ export default function SocketService(socketEventBus, vuexStore) {
     );
   };
 
-  let chat = function(message) {
+  let chat = function (message) {
     ioClient.emit('chat', message);
   };
   return {