Skip to content

Commit

Permalink
added cors
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Rothenbücher committed Jan 25, 2021
1 parent a287343 commit 6464362
Showing 3 changed files with 21 additions and 12 deletions.
14 changes: 4 additions & 10 deletions main.js
Original file line number Diff line number Diff line change
@@ -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 = {};
16 changes: 15 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",

0 comments on commit 6464362

Please sign in to comment.