Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sendRequest: function(){
const self = this
axios({
method: self.componentConfig["method"],
url: self.componentConfig["action_path"],
data: self.componentConfig["data"],
headers: {
'X-CSRF-Token': document.getElementsByName("csrf-token")[0].getAttribute('content')
}
}
)
.then(function(response){
if (self.componentConfig["success"] != undefined && self.componentConfig["success"]["emit"] != undefined) {
matestackEventHub.$emit(self.componentConfig["success"]["emit"], response.data);
}
// transition handling
if (self.componentConfig["success"] != undefined
&& self.componentConfig["success"]["transition"] != undefined
firstName: 'Fred',
lastName: 'Flintstone'
}
}).then(r => {
// $ExpectError
(r.status: string);
});
class AxiosExtended extends axios.Axios {
specialPut(...args) {
return super.put(...args);
}
}
const extended = new AxiosExtended();
axios.all([
extended.specialPut('foo')
.then((r) => {
// $ExpectError
(r.statusText: number)
}),
Promise.reject(12)
]).then(([a, b]) => {
// $ExpectError
(a: string);
})
app.post("/login", async (req, res, next) => {
try {
// client uses basic-auth
const auth = req.get('authorization');
const [username, password] = Buffer.from(auth.replace(/^\w+\s/, ''), 'base64').toString('utf8').split(':');
const { data: user } = await axios.post(endpoints.loginUrl, {
username,
password,
});
helpers.setAuthenticated(req, res, user.id)
.status(200)
.send('OK');
} catch (e) {
res.status(401).end();
}
});
import axios from 'axios'
import qs from 'qs';
import store from '../store/'
import router from '../router/'
// axios ้
็ฝฎ
axios.defaults.timeout = 10000;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8;multipart/form-data;boundary=----WebKitFormBoundaryeOOd9EoQVo6B4Tgb';
// /api่ฟไธชไฝ็ฝฎๅจconfig/index.js้้ข่ฎพ็ฝฎไบไปฃ็๏ผๆๅ localhost:8081/api่ฟไธชๅๅฐๅฐๅ
axios.defaults.baseURL = 'http://localhost:8081/api';
// http request ๆฆๆชๅจ
axios.interceptors.request.use(
config => {
if (store.state.token) { // ๅคๆญๆฏๅฆๅญๅจtoken๏ผๅฆๆๅญๅจ็่ฏ๏ผๅๆฏไธชhttp header้ฝๅ ไธtoken
config.headers.Authorization = `Bearer ${store.state.token}`;
}
console.log(config);
return config;
},
err => {
return Promise.reject(err);
});
import { _set,_get,_remove } from 'base/js/cookie'
// ๆฏๆฌก่ฏทๆฑๆบๅธฆLOGIN_TOKEN
axios.interceptors.request.use(
config => {
if (_get('_TOKEN_')) { // ๅคๆญๆฏๅฆๅญๅจtoken๏ผๅฆๆๅญๅจ็่ฏ๏ผๅๆฏไธชhttp header้ฝๅ ไธtoken
config.headers._TOKEN_ = _get('_TOKEN_');
}
return config;
},
err => {
return Promise.reject(err);
}
);
// ๆฏๆฌกๆฃๆฅTOKEN่ฟๆ
axios.interceptors.response.use(
response => {
if ( response.data.code == CONSTANT_CODE.TOKEN_MATURITY_LOGIN || response.data.code == CONSTANT_CODE.TOKEN_NOTUSER ) {
_remove('_TOKEN_')
store.commit(types.SET_NOW_USER_INFO,undefined)
router.replace({
path: '/login',
query: {redirect: router.currentRoute.fullPath}
})
} else if (response.data.code == CONSTANT_CODE.TOKEN_MATURITY) {
_remove('_TOKEN_')
store.commit(types.SET_NOW_USER_INFO,undefined)
}
return response;
},
err => {
return Promise.reject(err);
// text: 'ๅ ่ฝฝไธญ...',
// spinnerType: 'triple-bounce'
// });
return config;
}, function (error) {
// Do something with request error
Toast({
message: "ๆช็ฅ้่ฏฏ",
duration: 500
})
return Promise.reject(error);
});
// // ๅๅบๆฆๆชๅจ response
axios.interceptors.response.use(function (response) {
console.log(response)
// Indicator.close();
Toast({
message: response.data.msg,
duration: 500
});
if (response.data.code == '401') {
router.push({
name: 'login'
})
}
return response;
}, function (error) {
Toast({
message: "ๆช็ฅ้่ฏฏ",
duration: 500
// if (!checkLogin()) {
// window.location = '#login'
// return new Error('no login')
// }
// }
// config.withCredentials = true // ่ฎพ็ฝฎๆต่งๅจ่ชๅจๅญๅจๆๅกๅจcookie
let token = localStorage.getItem('token')
if (token) {
config.headers.Authorization = 'Bearer ' + token
}
return config
}, (error) => {
return Promise.reject(error)
})
// ๆทปๅ ๅๅบๆฆๆชๅจ
axios.interceptors.response.use(function (response) {
if (response.data.status !== 1) {
message.error(response.data.message);
}
return response.data
}, function (error) {
console.log(error)
// Toast.fail(error.message, 1);
return Promise.reject(error);
});
export default axios
return new Promise((resolve) => {
axios.request({
url,
// `method` ๆฏๅๅปบ่ฏทๆฑๆถไฝฟ็จ็ๆนๆณ
method: 'get', // ้ป่ฎคๆฏ get
// `onDownloadProgress` ๅ
่ฎธไธบไธ่ฝฝๅค็่ฟๅบฆไบไปถ
onDownloadProgress(progressEvent) {
// ๅฏนๅ็่ฟๅบฆไบไปถ็ๅค็
console.log('--------------------ไธ่ฝฝๅพ็่ฟๅบฆ:')
// console.log(progressEvent)
},
}).then(async (result) => {
if (result.status === 200) {
// eslint-disable-next-line no-param-reassign
result = result.data.data
} else {
return
module.exports = function updateGithubComment(commentID, message) {
/* /repos/:owner/:repo/issues/comments/:id */
const commentAPI = `https://api.github.com/repos/${GITHUB_REPO}/issues/comments/${commentID}`
return axios.patch(commentAPI, {
"body": message,
}, config).then(function(response) {
console.log('patch response', response)
return response
});
}
}).catch((error) => {
if (axios.isCancel(error)) {
console.log(error.message);
} else {
mock.restore(); //// JUST FOR MOCKING
dispatch({ type: types.FETCH_GROUPS_ERROR, error: error.response.data });
}
});
};