Commit bd486ce16fc24bfd7030fc51857a579776e12e68
1 parent
6b213cea
fix: set proxy for html2canvas
Showing
3 changed files
with
13 additions
and
1 deletions
back-end/h5-api/api/work/config/routes.json
back-end/h5-api/api/work/controllers/Work.js
| 1 | 1 | 'use strict'; |
| 2 | +const request = require('request'); | |
| 2 | 3 | |
| 3 | 4 | /** |
| 4 | 5 | * Read the documentation (https://strapi.io/documentation/3.0.0-beta.x/guides/controllers.html#core-controllers) |
| ... | ... | @@ -72,5 +73,8 @@ module.exports = { |
| 72 | 73 | const pageJSON = await strapi.services.work.parsePSD(ctx.request.body.files.file); |
| 73 | 74 | // eslint-disable-next-line |
| 74 | 75 | ctx.body = pageJSON; |
| 76 | + }, | |
| 77 | + corsProxy: async (ctx) => { | |
| 78 | + ctx.body = request(ctx.query.url); | |
| 75 | 79 | } |
| 76 | 80 | }; | ... | ... |
front-end/h5/src/utils/helper.js
| ... | ... | @@ -12,7 +12,7 @@ export function takeScreenshot (selector = '.canvas-wrapper', fileName = `${+new |
| 12 | 12 | // allowTaint: Whether to allow cross-origin images to taint the canvas |
| 13 | 13 | // if you use allowTaint: true, the cors image will taint the canvas, and canvas.toDataURL won't work |
| 14 | 14 | // 会对canvas造成污染,导致 canvas.toDataURL 无效 |
| 15 | - html2canvas(el, { allowTaint: true }).then(canvas => { | |
| 15 | + html2canvas(el, { proxy: '/works/cors-proxy' }).then(canvas => { | |
| 16 | 16 | // document.body.appendChild(canvas) use this line to test the generated canvas |
| 17 | 17 | canvas.toBlob(blob => { |
| 18 | 18 | const file = new window.File([blob], fileName, { type: 'image/png' }) | ... | ... |