add cors, needed for dev mode at least

This commit is contained in:
Thomas Ruoff
2017-02-18 01:04:03 +01:00
parent d806327bf9
commit b9424abebf
3 changed files with 5 additions and 6 deletions

View File

@@ -1,7 +1,6 @@
{ {
"env": { "env": {
"node": true, "node": true,
"browser": true,
"es6": true "es6": true
}, },
"parserOptions": { "parserOptions": {
@@ -74,8 +73,5 @@
"space-infix-ops": 2, "space-infix-ops": 2,
"strict": [2, "global"], "strict": [2, "global"],
"wrap-iife": 2 "wrap-iife": 2
},
"globals": {
"chrome": true
} }
} }

View File

@@ -1,12 +1,14 @@
const express = require('express'); const express = require('express');
const bodyParser = require('body-parser'); const bodyParser = require('body-parser');
const cors = require('cors');
const app = express(); const app = express();
const templates = require('./templates'); const templates = require('./templates');
const renderer = require('./renderer'); const renderer = require('./renderer');
app.use(bodyParser.json()); app.use(bodyParser.json());
app.post('/generate/pdf/:template', (req, res) => { app.options('/generate/pdf/:template', cors());
app.post('/generate/pdf/:template', cors(), (req, res) => {
const templateName = req.params.template; const templateName = req.params.template;
const options = req.body; const options = req.body;
@@ -24,7 +26,7 @@ app.post('/generate/pdf/:template', (req, res) => {
res.sendStatus(500).end('Something went wrong while baking the PDF'); res.sendStatus(500).end('Something went wrong while baking the PDF');
return; return;
} }
res.set('Content-Type', 'application/pdf'); res.setHeader('Content-Type', 'application/pdf');
res.send(pdf); res.send(pdf);
res.end(); res.end();
}); });

View File

@@ -13,6 +13,7 @@
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"body-parser": "^1.16.1", "body-parser": "^1.16.1",
"cors": "^2.8.1",
"express": "^4.14.1", "express": "^4.14.1",
"preact": "^7.2.0", "preact": "^7.2.0",
"preact-router": "^2.4.1" "preact-router": "^2.4.1"