Security News
Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
request-pre
Advanced tools
Readme
format data before request send
// services/index.js
import Service from 'request-pre';
import apiSchemaList from './apis';
if (process.env.NODE_ENV === 'development') {
const mocks = require('./mocks');
Object.keys(mocks).forEach((methodName) => {
if (apiSchemaList[methodName]) {
apiSchemaList[methodName].mock = mocks[methodName];
}
});
}
const serviceConfig = {
prefix: '/domain',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
config: {
custom: 'option',
},
};
const service = new Service(apiSchemaList, serviceConfig, function ({config, url, mock}) {
// requester
const { path, query, body, method, headers } = url;
return Promise.resolve({
config,
mock,
...url,
});
});
service.list = function(...args) {
return service.$list(...args).then((data) => {
console.log('rewrite list');
return data;
});
};
// not do this
// service.$list = function(...args) {
// return Promise.reject('');
// }; will throw error
// services/apis.js
export default {
list: {
url: {
path: '/a/b/{id}',
method: methods.GET,
query: {
search: 1,
},
headers: {
'x-option': 'custom',
},
},
},
detail: {
url: {
path: '/a/b/{id}', // support path param
method: methods.POST,
query: {
search: 1,
},
body: {
name: 'test',
},
headers: {
'x-option': 'custom',
},
},
},
};
// services/mocks.js
export default {
list: {
mock: {
'list.success': {
success: true,
data: [], // or () => [],
},
},
},
};
// case
import service from '../services';
services.list({
path: {
id: 2,
},
query: {
status: 4,
},
body: {
xx: 2,
},
headers: {
'x-option': 'custom',
'Content-Type': 'application/x-www-form-urlencoded'
},
config: {
mock: 'list.success',
},
});
// before send data
{
"config": {
"custom": "option",
"mock": "list.success"
},
"mock": {
"mock": {
"list.success": {
"success": true,
"data": []
}
}
},
"url": {
"path": "/domain/a/b/2",
"method": "GET",
"query": {
"search": 1,
"status": 4
},
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"x-option": "custom"
}
}
}
FAQs
process format data before request send
The npm package request-pre receives a total of 1,062 weekly downloads. As such, request-pre popularity was classified as popular.
We found that request-pre 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
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.