axios

CSRF InvalidAuthenticityToken with rails and react

☆樱花仙子☆ 提交于 2020-01-03 21:08:11
问题 I can't get my code working with the CSRF-Token. I have a axiosconfig file where I setup axios and export it: import axios from 'axios' const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content') const instance = axios.create({ baseURL: 'http://api.domain.tld/v1/', headers: { 'X-CSRF-Token': csrfToken } }); export default instance and my react component where I import it: import axios from '../config/axios' in my form on submit I fire this Post: axios .post('

react with Rails 5, getting CSRF error for post with axios

↘锁芯ラ 提交于 2020-01-03 10:59:20
问题 I'm trying to use react_on_rails to build my first example with react and rails. I'm trying to save some data to the rails backend, using axios for the ajax. here's my code: import store from "../store/helloWorld"; import axios from "axios"; export const SAVE_NAME = "SAVE_NAME"; export function saveNameAction(name) { return { type: SAVE_NAME, name }; } export function saveName(name) { axios .post("/hello_world", saveNameAction(name)) .then(function(response) { console.log(response); }) .catch

Matching axios POST request with moxios

╄→尐↘猪︶ㄣ 提交于 2020-01-03 10:44:53
问题 Is it possible to use moxios to mock a reply to a POST request that will match not just by URL but also by the POST body? Inspecting the body afterwards would work for me too. This is what I am doing now. As far as I know there are no method specific stubbing methods: describe('createCode', function () { it('should create new code', function () { moxios.stubRequest(process.env.API_URL + '/games/GM01/codes', { status: 200 }) }) }) 回答1: There is a way to inspect the last axios request using

Matching axios POST request with moxios

扶醉桌前 提交于 2020-01-03 10:44:17
问题 Is it possible to use moxios to mock a reply to a POST request that will match not just by URL but also by the POST body? Inspecting the body afterwards would work for me too. This is what I am doing now. As far as I know there are no method specific stubbing methods: describe('createCode', function () { it('should create new code', function () { moxios.stubRequest(process.env.API_URL + '/games/GM01/codes', { status: 200 }) }) }) 回答1: There is a way to inspect the last axios request using

axios.patch / axios.put is not working in Vue and Laravel

强颜欢笑 提交于 2020-01-03 08:40:10
问题 I have this code in my vue file saveProfile() { axios.patch('/api/pegawai/' + this.id, { data: this.data }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }); } and in my laravel controller public function update(Request $request, $id){ return $this->sendResponse('request retrieved'); } public function sendResponse($message){ $response = [ 'success' => true, 'message' => $message, ]; return response()->json($response, 200); } when i run the

How to use 2 instances of Axios with different baseURL in the same app (vue.js)

二次信任 提交于 2020-01-03 08:26:11
问题 I'm trying to learn vue.js so I made a little app that displays news articles from an API and, in another view, allows the user to log into another server. For this I'm using Axios. I know I got it to work pretty well at some point, but today when starting my project, it's just impossible to get both apis to work simultaneously. Here is my login service: import axiosTrainingAPI from 'axios' axiosTrainingAPI.defaults.baseURL = 'https://api.**********.com' const trainingAPI = { login

DRF & axios - token auth not returning token with axios, but does with curl

我们两清 提交于 2020-01-03 05:50:54
问题 If I run this curl command, it works: -> curl -X POST http://localhost:8000/api/token-auth/ --data "username=garfonzo&password=garfonzo" -> {"token":"79b2428019994713d61bb2f728ae62ae8c8be9ee"}% But if I do the following with axios, it fails with a 401 returned: const API_URL = 'http://localhost:8000/api/' const LOGIN_URL = API_URL + 'token-auth/' // "creds" in this situation is a dict of { username: 'garfonzo', password: 'garfonzo' } axios.post(LOGIN_URL, creds).then((response) => {

node.js - Passport not persisting across browser requests, works with Postman

倖福魔咒の 提交于 2020-01-03 03:38:06
问题 I am currently using the create-react-app boiler plate and have been attempting to add auth. I am using axios as my promise based HTTP libray with React.js. I have been using node with express, express-session, passport and passport-local on the backend. Here is my server.js file with some exlusions: const express = require('express'); const mysql = require('mysql'); const app = express(); const cors = require('cors'); const session = require('express-session'); const passport = require(

Can't make post with axios to Laravel App

人盡茶涼 提交于 2020-01-03 03:19:07
问题 i tried many times to post an ajax request with axios using vuejs to lararvel app i added the csrf_token() in meta master blade. but the status always returns as 419 (Unknown Status), If some has got similar type of error then please help. 回答1: You must assign value of csrf_token() to some field in your layout file. I would suggest you use like this: <meta name="csrf-token" content="{{ csrf_token() }}"> If you are using Laravel mix to compile your JS & CSS, then the csrf_token is

VueJs local assets path

江枫思渺然 提交于 2020-01-02 16:17:15
问题 I'm working on a Vuejs App. based on Quasar Framework , in src/components/Hello.vue there i have a function to load json file axios.get('../assets/json/ar/myfile.json') .then(response => { // JSON responses are automatically parsed. console.log(response) }) .catch(e => { this.errors.push(e) }) it returns error, GET http://localhost:8080/assets/json/ar/ch78.json 404 (Not Found) so my question is how to get the file from src/assets folder ? axios.get('../assets/json/ar/myfile.json') this line