Authored by htoooth

fix

@@ -364,7 +364,6 @@ const profile_controller = { @@ -364,7 +364,6 @@ const profile_controller = {
364 const column = ctx.query.column; 364 const column = ctx.query.column;
365 const result = await sourceMap(fileUrl, line, column).catch(console.log); 365 const result = await sourceMap(fileUrl, line, column).catch(console.log);
366 366
367 - console.log(result)  
368 ctx.body = { 367 ctx.body = {
369 file: result.sourcesContent, 368 file: result.sourcesContent,
370 source: result.source, 369 source: result.source,
1 // 查找sourcemap 1 // 查找sourcemap
2 2
3 -const request = require('superagent');  
4 const sourceMap = require('source-map'); 3 const sourceMap = require('source-map');
5 const config = require('../../../config/config'); 4 const config = require('../../../config/config');
6 const url = require('url'); 5 const url = require('url');
  6 +const path = require('path');
  7 +const fs = require('fs');
7 8
8 const sourcesPathMap = {}; 9 const sourcesPathMap = {};
9 10
  11 +async function readFile(url) {
  12 + const filePath = path.join(config.sourceMap, url + '.map');
  13 +
  14 + return new Promise(function(resolve, reject) {
  15 + fs.readFile(filePath, function(err, data) {
  16 + if (err) {
  17 + reject(err);
  18 + return;
  19 + }
  20 +
  21 + resolve(data);
  22 + })
  23 +
  24 + });
  25 +}
  26 +
10 function fixPath(filepath) { 27 function fixPath(filepath) {
11 return filepath.replace(/\.[\.\/]+/g, ""); 28 return filepath.replace(/\.[\.\/]+/g, "");
12 } 29 }
@@ -17,11 +34,7 @@ async function lookupSourceMap(fileUrl, line, column) { @@ -17,11 +34,7 @@ async function lookupSourceMap(fileUrl, line, column) {
17 } 34 }
18 35
19 const urlPath = url.parse(fileUrl).pathname; 36 const urlPath = url.parse(fileUrl).pathname;
20 -  
21 - const {body: content} = await request.get(`${config.sourceMap.domain}/api/sourcemap/load`)  
22 - .responseType('blob')  
23 - .query({path: urlPath});  
24 - 37 + const {body: content} = await readFile(urlPath);
25 const fileContent = content.toString(); 38 const fileContent = content.toString();
26 const fileObj = JSON.parse(fileContent); 39 const fileObj = JSON.parse(fileContent);
27 const sources = fileObj.sources; 40 const sources = fileObj.sources;
@@ -76,9 +76,7 @@ const defaults = { @@ -76,9 +76,7 @@ const defaults = {
76 // redis key prefix 76 // redis key prefix
77 singleBrandKeyPre: 'golobal:yoho:single_brand:', // key: 品牌id, val: 名牌名 77 singleBrandKeyPre: 'golobal:yoho:single_brand:', // key: 品牌id, val: 名牌名
78 singleSortKeyPre: 'golobal:yoho:single_sort:', // key: 品类id, val: 品类名 78 singleSortKeyPre: 'golobal:yoho:single_sort:', // key: 品类id, val: 品类名
79 - sourceMap: {  
80 - domain: 'http://static-ci.yoho.cn'  
81 - }, 79 + sourceMap: '/home/yoho-node-ci/dist/'
82 }; 80 };
83 81
84 const specific = { 82 const specific = {