axios

displaying collection data from mongodb using axios in reactjs

a 夏天 提交于 2021-01-28 15:09:49
问题 I am new to MERN and I try to display data from mongodb collection using axios. I try to display a list of cities on the web page. I am not sure if I am doing it write. Should I use super state?jsonpostman Here is my reactjs code: import React, { Component } from 'react'; import axios from 'axios'; export class Cities extends Component { constaractor(state) { state = { locations:[] }; } componentDidMount() { axios.get('/cities') .then(cities => console.log(cities.data)) .catch(e => console

Getting 404 (Not Found) on axios.delete()

孤者浪人 提交于 2021-01-28 14:17:45
问题 I'm trying to implement the delete functionality for my survey creation app. I'm using MongoDB with mongoose for the database, node.js/Express for the backend server and React/Redux for the frontend side. Although I think I set routing correctly, I get 404 (Not Found) on axios.delete(). The error says that http://localhost:3000/api/surveys/delete/{the-survey-id-here} is not found. I have been reading the documentation of axios, Express, mongoose and other websites, however, nothing worked for

onChange not updating React

谁说胖子不能爱 提交于 2021-01-28 14:00:00
问题 I've been working on this project for the last couple of hours and I was pretty sure that this final hour would be my last. No errors are appearing. My thinking is that when I pick a hero from the drop down, the page will update depending on my choice. I may have something that isn't firing that I'm not picking up on. import React, {useEffect, useState} from 'react' import axios from 'axios' require("regenerator-runtime/runtime"); const App = () => { const [hero, selectedHero] = useState(

How to upload images to fastify + graphql backend with axios?

做~自己de王妃 提交于 2021-01-28 13:35:50
问题 When sending images via axios I found I have to use formdata. I add my images here but when sending the formdata my entire backend just freezes, just says "pending". Ive been following this And my attempt so far: backend: Apollo: import { ApolloServer, makeExecutableSchema } from 'apollo-server-fastify'; const schema = makeExecutableSchema({ typeDefs, resolvers }); const apolloServer = new ApolloServer({ schema, uploads: { maxFileSize: 10000000, maxFiles: 5, }, }); (async function() { app

Using Axios and Vue to fetch api data - returning undefined

跟風遠走 提交于 2021-01-28 11:11:12
问题 Running into a snag with trying to integrate my API with Vue/Axios. Basically, Axios is getting the data (it DOES console.log what I want)... But when I try to get that data to my empty variable (in the data object of my component) to store it, it throws an "undefined at eval" error. Any ideas on why this isn't working for me? Thanks! <template> <div class="wallet-container"> <h1 class="title">{{ title }}</h1> <div class="row"> {{ thoughtWallet }} </div> </div> </template> <script> import

Get response data from axios in vue.js

巧了我就是萌 提交于 2021-01-28 10:15:34
问题 I am trying to get the response data from my REST API and to display it in my vue.js application as follows: var database = new Vue({ el: '#database', data: { databaseConfiguration: { type: '', url: '', port: '', username: '', password: '' }, errors: [] }, created: function () { axios.get('/config/database') .then(function (response) { this.databaseConfiguration = response.data; console.log(response.data); }) .catch(function (error) { this.errors.push(error); console.log(error); }) } } ) If I

Axios get a file from URL and upload to s3

和自甴很熟 提交于 2021-01-28 07:19:30
问题 I'm trying to get files from a site using axios.get, and then uploading it directly to S3. However, the files are corrupted or not encoded properly, and can't be opened after upload. File types range from .jpg, .png to .pdf. Here is my code: axios.get(URL, { responseEncoding: 'binary', responseType: 'document', }).then((response) => { return new Promise((resolve, reject) => { const s3Bucket = nconf.get('AWS_S3_BUCKET'); s3.upload({ 'ACL': 'public-read', 'Body': response.data, 'Bucket':

Best way to handle API calls from frontend

て烟熏妆下的殇ゞ 提交于 2021-01-28 06:52:58
问题 Okay, so atm i have a frontend application built with Nuxt JS using Axios to do requests to my REST API(separate). If a user does a search on the website the API URL is visible in XMLHttprequests so everyone could use the API if they want to. What is the best way of making it so that only users that search through my website gets access to the API and people that just directly to the URL gets denied. I suppose using some sort of token system, but what is the best way to do it? JWT? (Users

Mongoose model not persisting object

一曲冷凌霜 提交于 2021-01-28 05:13:44
问题 In a nutshell, I'm working on a math assessment app that takes your answers and stores them in a database and I'm having trouble adding more than one object to the backend. The Mongoose model is as such: const mongoose = require('mongoose'); const Algebra1Schema = new mongoose.Schema({ user: { type: mongoose.Schema.Types.ObjectId, ref: 'user' }, answers: { type: Object }, date: { type: Date, default: Date.now } }) module.exports = algebra1 = mongoose.model('algebra1', Algebra1Schema) Here is

Axios returns promise pending

只愿长相守 提交于 2021-01-28 04:00:50
问题 i want this function to return either true or false, instead I get /** * Sends request to the backend to check if jwt is valid * @returns {boolean} */ const isAuthenticated = () => { const token = localStorage.getItem('jwt'); if(!token) return false; const config = {headers : {'x-auth-token' : token}}; const response = axios.get('http://localhost:8000/user' , config) .then(res => res.status === 200 ? true : false) .catch(err => false); return response; } export default isAuthenticated; I