Skip to content

Commit 6464362

Browse files
author
Michael Rothenbücher
committed
added cors
1 parent a287343 commit 6464362

3 files changed

Lines changed: 21 additions & 12 deletions

File tree

main.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ var Mustache = require('mustache');
1313
var express = require('express')
1414
var favicon = require('serve-favicon')
1515
var session = require('express-session')
16+
var cors = require('cors')
1617

1718
// express stuff
1819
var rest = express()
1920

21+
//cors
22+
rest.use(cors())
23+
2024
// ejs
2125
rest.set('view engine', 'ejs');
2226
rest.use(express.static(__dirname + '/html'));
@@ -36,8 +40,6 @@ rest.use(session({
3640
// JSON
3741
rest.use(express.json());
3842

39-
40-
4143
// datastorage stuff
4244
if (!fs.existsSync(__dirname + '/db')) {
4345
fs.mkdirSync(__dirname + '/db');
@@ -54,14 +56,6 @@ var http = require('http');
5456
// socket for sending data to the printer
5557
const Net = require('net');
5658

57-
// cors option
58-
rest.use(function(res, next) {
59-
res.header("Access-Control-Allow-Origin", "http://localhost:3000"); // use your own domain
60-
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
61-
res.header("Access-Control-Allow-Credentials", true)
62-
next();
63-
});
64-
6559
// Main
6660
rest.get('/', function(req, res) {
6761
var data = {};

package-lock.json

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zpl-rest",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Webservice for Zebra ZPL printing",
55
"main": "main.js",
66
"scripts": {
@@ -18,6 +18,7 @@
1818
"registry": "https://npm.pkg.github.com/"
1919
},
2020
"dependencies": {
21+
"cors": "^2.8.5",
2122
"diskdb": "^0.1.17",
2223
"ejs": "^3.0.1",
2324
"express": "^4.17.1",

0 commit comments

Comments
 (0)