mirror of
https://github.com/tomru/pdfer.git
synced 2026-03-03 06:27:19 +01:00
add cors, needed for dev mode at least
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
{
|
||||
"env": {
|
||||
"node": true,
|
||||
"browser": true,
|
||||
"es6": true
|
||||
},
|
||||
"parserOptions": {
|
||||
@@ -74,8 +73,5 @@
|
||||
"space-infix-ops": 2,
|
||||
"strict": [2, "global"],
|
||||
"wrap-iife": 2
|
||||
},
|
||||
"globals": {
|
||||
"chrome": true
|
||||
}
|
||||
}
|
||||
|
||||
6
index.js
6
index.js
@@ -1,12 +1,14 @@
|
||||
const express = require('express');
|
||||
const bodyParser = require('body-parser');
|
||||
const cors = require('cors');
|
||||
const app = express();
|
||||
const templates = require('./templates');
|
||||
const renderer = require('./renderer');
|
||||
|
||||
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 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');
|
||||
return;
|
||||
}
|
||||
res.set('Content-Type', 'application/pdf');
|
||||
res.setHeader('Content-Type', 'application/pdf');
|
||||
res.send(pdf);
|
||||
res.end();
|
||||
});
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.16.1",
|
||||
"cors": "^2.8.1",
|
||||
"express": "^4.14.1",
|
||||
"preact": "^7.2.0",
|
||||
"preact-router": "^2.4.1"
|
||||
|
||||
Reference in New Issue
Block a user