MCPcopy
hub / github.com/apache/echarts / rewrite

Function rewrite

test/runTest/server.js:75–92  ·  view source on GitHub ↗
(urlPrefix)

Source from the content-addressed store, hash-verified

73 // This is for visual test cases from `npm run test:visual:copy:examples`.
74 // NOTE: `server-handler` `rewrites` does not support to visit ancestor directories.
75 function rewrite(urlPrefix) {
76 if (request.url.startsWith(urlPrefix)) {
77 // request.url is like '/xxx/yyy'
78 const filePath = path.join(ECHARTS_EXAMPLES_DIR, request.url);
79 // console.log('custom rewrite: ', filePath, request.url);
80 if (path.extname(filePath) === '.json') {
81 // Then jQuery can automatically parse JSON string to JSON object.
82 // Some cases rely on that.
83 response.setHeader('Content-Type', 'application/json');
84 }
85 return fs.createReadStream(filePath)
86 .on('error', () => {
87 response.statusCode = 404;
88 response.end('Not found');
89 })
90 .pipe(response);
91 }
92 }
93 let rewriteResult;
94 if ((rewriteResult = rewrite('/public/data/asset/data'))
95 || (rewriteResult = rewrite('/e2e/e2e-asset'))

Callers 1

serveFunction · 0.85

Calls 1

pipeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…