Skip to content

Commit bd486ce

Browse files
committed
fix: set proxy for html2canvas
1 parent 6b213ce commit bd486ce

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

back-end/h5-api/api/work/config/routes.json

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
{
22
"routes": [
3+
{
4+
"method": "GET",
5+
"path": "/works/cors-proxy",
6+
"handler": "Work.corsProxy",
7+
"config": {
8+
"policies": []
9+
}
10+
},
311
{
412
"method": "GET",
513
"path": "/works",

back-end/h5-api/api/work/controllers/Work.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
const request = require('request');
23

34
/**
45
* Read the documentation (https://strapi.io/documentation/3.0.0-beta.x/guides/controllers.html#core-controllers)
@@ -72,5 +73,8 @@ module.exports = {
7273
const pageJSON = await strapi.services.work.parsePSD(ctx.request.body.files.file);
7374
// eslint-disable-next-line
7475
ctx.body = pageJSON;
76+
},
77+
corsProxy: async (ctx) => {
78+
ctx.body = request(ctx.query.url);
7579
}
7680
};

front-end/h5/src/utils/helper.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function takeScreenshot (selector = '.canvas-wrapper', fileName = `${+new
1212
// allowTaint: Whether to allow cross-origin images to taint the canvas
1313
// if you use allowTaint: true, the cors image will taint the canvas, and canvas.toDataURL won't work
1414
// 会对canvas造成污染,导致 canvas.toDataURL 无效
15-
html2canvas(el, { allowTaint: true }).then(canvas => {
15+
html2canvas(el, { proxy: '/works/cors-proxy' }).then(canvas => {
1616
// document.body.appendChild(canvas) use this line to test the generated canvas
1717
canvas.toBlob(blob => {
1818
const file = new window.File([blob], fileName, { type: 'image/png' })

0 commit comments

Comments
 (0)