/* * Helper to load request library * We do this for testing so we can stub axios and ensure it isn't auto cached * via require when we new Lando() */ const requestClient = () => { const axios = require('axios'); // @todo: is it ok to turn redirects off here? // if we don't we get an error every time http tries to redirect to https return axios.create({maxRedirects: 0, httpsAgent: new https.Agent({rejectUnauthorized: false})}); }
constructor(context) { this.context = context; this.credentials = new MicrosoftAppCredentials(process.env.MicrosoftAppId, process.env.MicrosoftAppPassword); this.client = axios.create({ baseURL: process.env.BotBaseUrl }); }
/* * Auth with pantheon and set the session */ auth(token = this.token) { const data = {machine_token: token, client: 'terminus'}; const options = (this.mode === 'node') ? {headers: {'User-Agent': 'Terminus/Lando'}} : {}; const upath = ['authorize', 'machine-token']; return pantheonRequest(axios.create({baseURL: this.baseURL}), this.log, 'post', upath, data, options) .then(data => { this.token = token; this.session = data; const headers = {'Content-Type': 'application/json'}; // Add cookie if we are in node mode, otherwise assume its set upstream in the browser if (this.mode === 'node') headers.Cookie = `X-Pantheon-Session=${data.session}`; this.request = axios.create({baseURL: this.baseURL, headers}); return data; }); }
report(action = 'unknown', data = {}) { // Get Stuff const log = this.log; const id = this.id; // Attempt to sanitize merged data as much as possible const send = cleanseData(_.merge({}, this.data, data, {action, created: new Date().toJSON()})); // Log the attempt log.verbose('reporting %s action to', action, this.endpoints); log.debug('reported data', send); // Start the reporting chain return Promise.resolve(this.endpoints) // Filter out any inactive endpoints .filter(endpoint => endpoint.report) // Get the client and report .map(endpoint => { const agent = axios.create({baseURL: endpoint.url}); // Post the data return agent.post('/metrics/v2/' + id, send).catch(error => { const url = _.get(endpoint, 'url', 'unknown'); const status = _.get(error, 'response.status', 'unknown'); const reason = _.get(error, 'response.statusText', 'unknown'); const message = _.get(error, 'response.data.message', 'unknown'); log.debug('metrics post to %s failed with %s (%s) %s', url, status, reason, message); }); }); }
axios.create.restore(); }); });
axios.create({ baseURL: 'https://question.hortor.net/', headers: { 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_1 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C153 MicroMessenger/6.6.1 NetType/WIFI Language/zh_CN', 'Content-Type': 'application/x-www-form-urlencoded' }, transformRequest: [data => querystring.stringify(data)] })
constructor ({access_token, account_id}) { this.request = axios.create({ headers: { ...headers, uid: account_id, // eslint-disable-next-line camelcase jwt: `Bearer ${access_token}` } }) }
constructor(opts) { opts = opts || {}; opts.port = opts.port || process.env.AURORA_PORT || 16021; opts.host = opts.host || process.env.AURORA_HOST; opts.token = opts.token || process.env.AURORA_TOKEN; this.apibase = `http://${opts.host}:${opts.port}/api/beta`; this.req = axios.create({ baseURL: `http://${opts.host}:${opts.port}/api/beta/${opts.token}` }); }
app.get('/test/get/error', (req, res, next) => { const instance = axios.create(); instance.interceptors.request.use(AxiosLogger.requestLogger, AxiosLogger.errorLogger); instance.interceptors.response.use(AxiosLogger.responseLogger, AxiosLogger.errorLogger); instance.get('http://localhost:3000/echo/notfound').catch(() => { res.sendStatus(404); }); });
constructor() { this.token = this.getToken(); this.requestHandler = axios.create({ baseURL: "https://discordapp.com/api/v6", headers: { Authorization: this.token, "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) htb_client/0.0.1" } }); }
app.get('/test/get', (req, res, next) => { const instance = axios.create({ headers: { 'X-Custom-Header': 'foobar' }, }); instance.interceptors.request.use(AxiosLogger.requestLogger); instance.interceptors.response.use(AxiosLogger.responseLogger); instance.get('http://localhost:3000/echo/get?echo=hello').then((data) => { res.json(200); }); });
constructor() { this.client = axios.create({ baseURL: 'https://api.github.com/', timeout: 5000, headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', 'Authorization': `Bearer ${process.env.GITHUB_AUTH_TOKEN}`, }, }) }
axios.create({ paramsSerializer: function (params) { return qs.stringify(params, { indices: false }) } })
constructor ({ url, timeout, apiKey }) { this.__client = axios.create({ baseURL: url, timeout, params: { apikey: apiKey } }) }