diff --git a/nodejs/index.js b/nodejs/index.js index fadcfda..1871e03 100644 --- a/nodejs/index.js +++ b/nodejs/index.js @@ -4,20 +4,22 @@ const express = require('express'); const http = require('http'); const socketio = require('socket.io'); const socketEvents = require('./utils/socket'); +let cors = require('cors'); class Server { - constructor() { - this.port = process.env.PORT || 3000; + constructor() { + this.port = process.env.PORT || 3000; this.host = process.env.HOST || `localhost`; this.app = express(); + this.app.use(cors()); this.http = http.Server(this.app); this.socket = socketio(this.http); - } + } - appRun(){ - new socketEvents(this.socket).socketConfig(); - this.app.use(express.static(__dirname + '/uploads')); + appRun() { + new socketEvents(this.socket).socketConfig(); + this.app.use(express.static(__dirname + '/uploads')); this.http.listen(this.port, this.host, () => { console.log(`Listening on http://${this.host}:${this.port}`); }); diff --git a/nodejs/package-lock.json b/nodejs/package-lock.json index a7e7f55..ab1032c 100644 --- a/nodejs/package-lock.json +++ b/nodejs/package-lock.json @@ -469,6 +469,15 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, + "cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "requires": { + "object-assign": "^4", + "vary": "^1" + } + }, "create-error-class": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/create-error-class/-/create-error-class-3.0.2.tgz", @@ -956,11 +965,13 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true + "bundled": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -973,15 +984,18 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "concat-map": { "version": "0.0.1", - "bundled": true + "bundled": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -1084,7 +1098,8 @@ }, "inherits": { "version": "2.0.3", - "bundled": true + "bundled": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -1094,6 +1109,7 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -1106,17 +1122,20 @@ "minimatch": { "version": "3.0.4", "bundled": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true + "bundled": true, + "optional": true }, "minipass": { "version": "2.2.4", "bundled": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -1133,6 +1152,7 @@ "mkdirp": { "version": "0.5.1", "bundled": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -1205,7 +1225,8 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true + "bundled": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -1215,6 +1236,7 @@ "once": { "version": "1.4.0", "bundled": true, + "optional": true, "requires": { "wrappy": "1" } @@ -1320,6 +1342,7 @@ "string-width": { "version": "1.0.2", "bundled": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -1975,6 +1998,11 @@ "path-key": "^2.0.0" } }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" + }, "object-component": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/object-component/-/object-component-0.0.3.tgz", diff --git a/nodejs/package.json b/nodejs/package.json index bf96684..af4c6e8 100644 --- a/nodejs/package.json +++ b/nodejs/package.json @@ -11,6 +11,7 @@ "license": "ISC", "dependencies": { "config": "^1.30.0", + "cors": "^2.8.5", "express": "^4.16.3", "moment": "^2.22.2", "mysql": "^2.15.0",