axios

Different baseURL for development and production with Nuxt.js

喜你入骨 提交于 2019-12-12 23:19:18
问题 How can I add a different baseURL for development and production? This is currently my nuxt.config.js module.exports = { mode: 'universal', ... axios: { // See https://github.com/nuxt-community/axios-module#options baseURL: 'http://10.8.0.1:8000', credentials: false }, ... } For npm run dev and npm run generate I would like to have different baseURL's. How can I do this? EDIT // nuxt.config.js export default { env: { baseUrl: process.env.BASE_URL || 'http://localhost:3000' } } console.log

What does “dispatch()” mean/do, and why is it used when we have .then() and .catch()

Deadly 提交于 2019-12-12 21:05:45
问题 I am new to ES6 and advanced javascript. I have seen examples of code using the axios http client like this: axios.xxx(...).then((res) => dispatch(success(res)) , (err)=> dispatch(error(err))) whereas I am doing: axios.xxx(...).then(function(res){...}).catch(function(err){...}); I tried to look up dispatch on MDN but only found DispatchEvent... which is not the same? I ask because although my code works, I am finding http error codes like 403 etc from my api are handled as errors by axios,

reactjs make https (not http) requests with axios

守給你的承諾、 提交于 2019-12-12 19:35:56
问题 I'm trying to make https requests to the server using axios. Most of the tutorials regarding axios specify how to make http requests. I make the requests whenever users login. Here is my current request: axios.post('/api/login/authentication', { email: email, password: password }) .then(response => { this.props.history.push('/MainPage') }) .catch(error => { console.log(error) }) Can anyone help me convert this to an https request? 回答1: All URLs have two parts Domain - http://yourdomain.com

Unable to fetch data from local json file by axios

一世执手 提交于 2019-12-12 13:48:55
问题 I am using axios library for fetching data from the local json file but when i make get request it gives me error 404 not found. Here is my file structure. and i am using this code for fetching the data. import React from 'react'; import axios from 'axios'; class Login extends React.Component{ constructor() { super(); this.handleSubmit = this.handleSubmit.bind(this); this.state = { username: null, password: null }; } handleSubmit = (e)=>{ e.preventDefault(); var username=e.target.username

Axios OPTIONS instead of POST Request. Express Rest API (CORS)

前提是你 提交于 2019-12-12 12:50:26
问题 Im trying to use Axios (and VueJs) to make a Cross Origin POST Request to my Rest Api (running on localhost). Instead of doing a POST request, it actually does a OPTIONS request to my Rest Api. This circumvents a middleware function that checks for a token and return 403. This is the login function router.post('/login', (req, res) => { User.authUser(req.body, (err, user) => { var passwordIsValid = bcrypt.compareSync(req.body.password, user.password); if (err) throw err; if (!user) { res.json(

How to get response times from Axios

本秂侑毒 提交于 2019-12-12 09:37:47
问题 Can anyone suggest any ways to get response times from Axios? I've found axios-timing but I don't really like it (controversial, I know). I'm just wondering if anyone else has found some good ways to log response times. 回答1: You can use the interceptor concept of axios. Request intercepor will set startTime axios.interceptors.request.use(function (config) { config.metadata = { startTime: new Date()} return config; }, function (error) { return Promise.reject(error); }); Response interceptor

Axios GET from local PHP just returns code instead of executing

瘦欲@ 提交于 2019-12-12 05:16:54
问题 The API I am trying to access has disabled CORS so I need to request on the server side. Utilizing React and Axios I am making a get request to the local php file which should execute cURL but am just getting the php code back instead of it executing <?php $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "https://api.darksky.net/forecast/myAPIKet/coords"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($curl); curl_close($curl) echo $result; return; ?> <script> let

React-Redux app testing action creator containing axios GET call

我是研究僧i 提交于 2019-12-12 04:04:13
问题 I am writing a react-redux app and in one of my action creators I am making an api request via axios Roughly, it looks something like this: import axios from 'axios' export function getStoredData(userInput) { . . . var url = generateURL(userInput); var response = axios.get(url); return { type: GET_STORED_DATA payload: repsonse; }; } I wanted to mock axios using axios-mock-adapter but I don't quite understand how to do that, especially since I wouldn't want to modify my action creator for the

Axios React - not setting state, what am I doing wrong?

╄→尐↘猪︶ㄣ 提交于 2019-12-12 03:59:17
问题 So here's the code, I simply want to use axios to get, then set that response to the state. Using ES6 arrow functions import React, { Component } from 'react'; import './App.css'; import axios from 'axios'; class FieldValues extends Component { constructor (props){ super(props); this.state = { todos: [] } } componentDidMount() { axios.get(`127.0.0.1:8000/api/todos/`) .then(res => { this.setState({res.data}); }); } render(){ console.log(this.state); } } export default FieldValues; Here's a

Handling form data with flask request

♀尐吖头ヾ 提交于 2019-12-12 03:02:29
问题 I am using flask-restful as an api server and am constructing the first PUT method. Using request imported from flask, I am able to access request.form data without issue with the following cURL command: curl http://127.0.0.1:5000/api/v1/system/account -X PUT -d username=asdas -d email=asdasd@test.com My PUT method logs out both the username and email without issue: def put(self): print 'SystemAccountPut' print request.form['username'] print request.form['email'] return Output: