jayli-server
Advanced tools
Comparing version 0.0.25 to 0.1.0
// 'use strict'; | ||
var util = require('util'); | ||
var fs = require('fs'); | ||
var url = require('url'); | ||
var path = require('path'); | ||
@@ -10,2 +11,4 @@ var pwd = process.cwd(); | ||
var joinbuffers = require('joinbuffers'); | ||
var Entities = require('html-entities').AllHtmlEntities; | ||
entities = new Entities(); | ||
@@ -43,4 +46,8 @@ var reg = '--#(chunk)(\\s([a-z]+)=[\'"](.+?)[\'"])*--'; | ||
var includefile = hasIncludes(content); | ||
http.get(('http://'+includefile).replace(/^http:\/\/http:\/\//i,'http://'), function(res) { | ||
var reqUrlObj = url.parse(('http://' + includefile).replace(/^http:\/\/http:\/\//i,'http://'), true); | ||
http.get(Object.assign(reqUrlObj, { | ||
headers: { | ||
referer: 'http://m.taobao.com' | ||
} | ||
}), function(res) { | ||
var buffs = []; | ||
@@ -50,3 +57,10 @@ res.on('data',function(chunk){ | ||
}).on('end',function(){ | ||
var buff = joinbuffers(buffs); | ||
var buff = joinbuffers(buffs); | ||
if (/api\.alitrip\.com\/ems\/common/.test(includefile)) { | ||
buff = buff.toString('utf-8'); | ||
buff = entities.decode(buff); | ||
var fn = 'var ' + reqUrlObj.query.callback + '=function(v){return v;};' + buff; | ||
var emsContent = eval(fn); | ||
buff = emsContent.toString().replace(/^function\s*\(\)\{\/\*|\*\/\}$/mg, ''); | ||
} | ||
var newchunk = content.replace(new RegExp(reg,'i'),parseChunk2String(buff)); | ||
@@ -53,0 +67,0 @@ callback(newchunk); |
@@ -11,2 +11,3 @@ /** | ||
var fs = require('fs'); | ||
var url = require('url'); | ||
var pwd = process.cwd(); | ||
@@ -224,3 +225,3 @@ var path = require('path'); | ||
var i, len, ret, fileCont, incVars, absPath; | ||
var incFile = ctx.incFile; | ||
var incFile = decodeURIComponent(ctx.incFile); | ||
var incProps = ctx.incProps; | ||
@@ -314,3 +315,2 @@ var filePath = ctx.filePath; | ||
var repReg = new RegExp((val_insert + '|' + include), 'g'); | ||
return cont.replace(repReg, function(m, expr, incProps){ | ||
@@ -348,3 +348,11 @@ var ctx = get_context({ | ||
cont = cont.replace(new RegExp(tms_include, 'ig'),function(matchPath, tmsPath, encoding, tmsdir){ | ||
return "<!--#include " + 'virtual="http://' + path.join(tmsPrefix, tmsPath) + '" -->'; | ||
// tmsPath: rgn/ems/alitrip-common/flight-onsale/entry | ||
tmsPath = tmsPath.replace(/^\//, ''); // remove start `/` | ||
if (/ems\/alitrip\-(common|flight|hotel|train|destination|member|ticket|travel)/.test(tmsPath)) { | ||
// use miday interface | ||
var tmsParts = /ems\/alitrip-([a-zA-Z0-9_]+)\/([^,]*)/g.exec(tmsPath); | ||
var emsReqProxy = 'http://api.alitrip.com/ems/' + tmsParts[1] + '?charset=utf-8&callback=handle_tms_fragment_jayliserver&path=' + tmsParts[2]; | ||
return "<!--#include " + 'virtual="' + encodeURIComponent(emsReqProxy) + '" -->'; | ||
} | ||
return "<!--#include " + 'virtual="http://' + url.resolve(tmsPrefix, tmsPath) + '" -->'; | ||
}); | ||
@@ -351,0 +359,0 @@ |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "0.0.25", | ||
"version": "0.1.0", | ||
"description": "A node.js module for delivering static files,width ssi,mock and php", | ||
@@ -19,2 +19,3 @@ "keywords": [ | ||
"dependencies": { | ||
"html-entities": "^1.2.0", | ||
"iconv-lite": "", | ||
@@ -21,0 +22,0 @@ "joinbuffers": "~0.1.1", |
239810
2785
5
5
+ Addedhtml-entities@^1.2.0
+ Addedhtml-entities@1.4.0(transitive)