
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
一个本地模拟接口
npm install test-ajax
var test_ajax = require('test-ajax');
test_ajax({
base: './',//项目根目录
prot: 90, //端口
cache_path: "./__cache/", //缓存文件的路径,基于base
global: {
test: '我是测试的'
},
admin: '/admin/', //后台域,基于url
doc: '/doc/', //文档域,基于url
open: true,//是否打开浏览器
beforeSend: function(req, res){//请求前回调,返回false则不请求接口,这里不算静态资源,后台,文档
}
});
number, 端口,默认90
string, 缓存目录,基于base(文件路径)
object, 通用参数,在返回值里使用,如:
({
global:{
'500': 500,
'404': '{"errcode": "404"}'
}
})
返回值里使用(注:需要开启编译):
<%=global['500']%>
<%=global['404']%>
string, 后台路径,url开始
string, 文档路径,url开始
boolean, 是否打开浏览器
jsonpnode-combo时的处理(ps:下一个要研究的东西就是node-combo&&单元测试)编译返回值模板里提供以下方法:
/**
* 获取get的参数
* @type {Object}
*/
get
/**
* 获取post的参数
* @type {Object}
*/
post
/**
* 获取配置参数中global对象
* @type {Object}
*/
global
/**
* 设置header头信息
* @param {string} name 名称
* @param {string} val 值
*/
setHeader: function(name, val){
}
/**
* 设置响应状态码
* @param {number} code 状态码
*/
setStatus: function(code){
}
/**
* 设置延迟时间
* @param {number} time 延迟时间,ms
*/
setDelay: function(time){
}
/**
* 设置jsonp参数名
* @param {string} name 参数名
*/
setCallback: function(name){
}
Date
parseInt
parseFloat
Math
/**
* 格式化时间
* @param {string} str 格式化的样式
* @param {number|Date|undefined} date 时间缀,时间对象,空
* @return {string} 结果
*/
function dateFormat(str, date) {
}
/**
* 美化时间缀
* @param {number} time 时间缀,13位
* @return {string} 结果
*/
function dateElapsed(time) {
}
这套机制适合我吧,因为我们项目静态域单独,但接口是以根目录开始的,比如我使用的目录大概是:
本地静态:static.xx.me/
tpl/ html模板
js/ js文件,这里写接口都是以 url: '/api/login' 方式,因为到后端(线上)时就是这个目录
css/ 样式
api/ 本地接口测试
以上是本地环境,接口使用test-ajax调试
线上静态:static.xx.me/
js/ js文件,这里写接口都是以 url: '/api/login' 方式,因为到后端(线上)时就是这个目录
css/ 样式
线上正式: www.xx.com/
api/ 接口目录
以上是正式环境,接口走正式的server端,无需切换
当然test-ajax只是一种思路,适合自己项目的才是最好的~
FAQs
The npm package test-ajax receives a total of 32 weekly downloads. As such, test-ajax popularity was classified as not popular.
We found that test-ajax demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.