From 64643626fce98fff512f41d13bc8416cec38b25c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Rothenb=C3=BCcher?= Date: Mon, 25 Jan 2021 09:08:45 +0100 Subject: [PATCH] added cors --- main.js | 14 ++++---------- package-lock.json | 16 +++++++++++++++- package.json | 3 ++- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/main.js b/main.js index 3956cf7..3643859 100644 --- a/main.js +++ b/main.js @@ -13,10 +13,14 @@ var Mustache = require('mustache'); var express = require('express') var favicon = require('serve-favicon') var session = require('express-session') +var cors = require('cors') // express stuff var rest = express() +//cors +rest.use(cors()) + // ejs rest.set('view engine', 'ejs'); rest.use(express.static(__dirname + '/html')); @@ -36,8 +40,6 @@ rest.use(session({ // JSON rest.use(express.json()); - - // datastorage stuff if (!fs.existsSync(__dirname + '/db')) { fs.mkdirSync(__dirname + '/db'); @@ -54,14 +56,6 @@ var http = require('http'); // socket for sending data to the printer const Net = require('net'); -// cors option -rest.use(function(res, next) { - res.header("Access-Control-Allow-Origin", "http://localhost:3000"); // use your own domain - res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); - res.header("Access-Control-Allow-Credentials", true) - next(); -}); - // Main rest.get('/', function(req, res) { var data = {}; diff --git a/package-lock.json b/package-lock.json index f7c27d5..c1dc50c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "zpl-rest", - "version": "0.9.0", + "version": "1.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -158,6 +158,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" + } + }, "dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -564,6 +573,11 @@ "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==" }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" + }, "on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", diff --git a/package.json b/package.json index 4387ecb..c42e431 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zpl-rest", - "version": "1.0.0", + "version": "1.0.1", "description": "Webservice for Zebra ZPL printing", "main": "main.js", "scripts": { @@ -18,6 +18,7 @@ "registry": "https://npm.pkg.github.com/" }, "dependencies": { + "cors": "^2.8.5", "diskdb": "^0.1.17", "ejs": "^3.0.1", "express": "^4.17.1",