axios

node and reactjs axios server request returning index.html file instead of json

假如想象 提交于 2020-08-22 07:09:07
问题 I have setup my project with a react frontend being compiled by webpack and the server running on node and express. When I deploy to production my requests to the server are returning the index.html file in the 'dist' folder rather than the json with the data. My webpack compiled output is at the location ./dist. Here is the routing part of my server.js file: if (process.env.NODE_ENV === 'production') { app.use(express.static('dist')); const path = require('path'); app.get('/', (req, res) =>

node and reactjs axios server request returning index.html file instead of json

为君一笑 提交于 2020-08-22 07:09:06
问题 I have setup my project with a react frontend being compiled by webpack and the server running on node and express. When I deploy to production my requests to the server are returning the index.html file in the 'dist' folder rather than the json with the data. My webpack compiled output is at the location ./dist. Here is the routing part of my server.js file: if (process.env.NODE_ENV === 'production') { app.use(express.static('dist')); const path = require('path'); app.get('/', (req, res) =>

XMLHttpRequest blocked by CORS policy when posting data to a Web App

不羁岁月 提交于 2020-08-20 12:11:09
问题 I get a CORS error response when I tried to post my data to my Google Spreadsheet via a Web App. This is the error I get: Access to XMLHttpRequest at 'myGoogleSpreadSheetApiURL' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. I did some solution, I searched on internet but I can't solve the issue... I could already get my JSON data

vue全家桶项目学习(四、axis)

左心房为你撑大大i 提交于 2020-08-20 08:58:19
一、安装与使用 安装 npm install -S axios 使用 import axios from 'axios' ; export default { mounted ( ) { axios.post ( 'http://xxx.xxx.xxx.xxx/getInfo' , { param: 'test' } ) .then ( res = > { .. . } ) .catch ( err = > { .. . } ) } } 二、跨域 vue.config.js 中设置代理 module.exports = { devServer: { // 服务器地址 proxy: 'http://xxx.xxx.xxx.xxx' } } axios.post ( '/getInfo' , { param: 'test' } ) .then ( res = > { .. . } ) .catch ( err = > { .. . } ) 懒得写了,还可自己封装(生产与开发环境baseUrl,header,请求拦截,响应拦截…)。可在单独写一个js文件进行封装,然后在main.js中引入, vue.prototype.$xxx = xxx 在原型中定义,然后直接在组件中 this.$xxx() 使用。 参考: https://www.kancloud.cn/yunye/axios

🏃♀️点亮你的Vue技术栈,万字Nuxt.js实践笔记来了~

空扰寡人 提交于 2020-08-19 23:24:51
前言 作为一位 Vuer(vue开发者),如果还不会这个框架,那么你的 Vue 技术栈还没被点亮。 Nuxt.js 是什么 Nuxt.js 官方介绍: Nuxt.js 是一个基于 Vue.js 的通用应用框架。 通过对客户端/服务端基础架构的抽象组织,Nuxt.js 主要关注的是应用的 UI渲染。 我们的目标是创建一个灵活的应用框架,你可以基于它初始化新项目的基础结构代码,或者在已有 Node.js 项目中使用 Nuxt.js。 Nuxt.js 预设了利用 Vue.js 开发服务端渲染的应用所需要的各种配置。 如果你熟悉 Vue.js 的使用,那你很快就可以上手 Nuxt.js 。开发体验也和 Vue.js 没太大区别,相当于为 Vue.js 扩展了一些配置。当然你对 Node.js 有基础,那就再好不过了。 Nuxt.js 解决什么问题 现在 Vue.js 大多数用于单页面应用,随着技术的发展,单页面应用已不足以满足需求。并且一些缺点也成为单页面应用的通病,单页面应用在访问时会将所有的文件进行加载,首屏访问需要等待一段时间,也就是常说的白屏,另外一点是总所周知的 SEO 优化问题。 Nuxt.js 的出现正好来解决这些问题,如果你的网站是偏向社区需要搜索引擎提供流量的项目,那就再合适不过了。 我的第一个 Nuxt.js 项目 我在空闲的时间也用 Nuxt.js 仿掘金 web

CSharp Web实现文件上传下载功能实例解析

二次信任 提交于 2020-08-19 23:16:59
以ASP.NET Core WebAPI 作后端 API ,用 Vue 构建前端页面,用 Axios 从前端访问后端 API ,包括文件的上传和下载。 准备文件上传的API #region 文件上传 可以带参数 [HttpPost("upload")] public JsonResult uploadProject(IFormFile file, string userId) { if (file != null) { var fileDir = "D:\\aaa"; if (!Directory.Exists(fileDir)) { Directory.CreateDirectory(fileDir); } //文件名称 string projectFileName = file.FileName; //上传的文件的路径 string filePath = fileDir + $@"\{projectFileName}"; using (FileStream fs = System.IO.File.Create(filePath)) { file.CopyTo(fs); fs.Flush(); } return Json("ok"); }else{ return Json("no"); } } #endregion 前端vue上传组件 ( 利用Form表单上传 )

# Vue Axios Post 请求后端request.getParameterMap()拿不到值

余生颓废 提交于 2020-08-19 19:54:52
Vue Axios Post 请求后端request.getParameterMap()拿不到值 后端Form表单提交ConteentType类型 application/x- www-form-urlencoded 是 Post 请求默认的请求体内容类型,也是 form 表单默认的类型。 Servlet API 规范中对该类型的请求内容提供了 request.getParameter() 方法来获取请求参数值。 当请求类型不是Form表单提交的类型时候可以用下面方法取参数 VueAxios post 提交时候默认提交Json格式的,后端使用``````request.getParameter() 拿不到相应的参数值,可以使用 param = request.getReader().readLine();```这个方法拿到值,但是得到的是String 类型的参数,不好处理。就是如下图所示的问题。 还是处理一下 Vue axios 的提交方式,修改如下 export function requireData ( url , params , type , item ) { if ( ! url ) return false switch ( item ) { case 'back' : url = axios . defaults . baseM1URL + url break ;

How to cascade a file uploaded in react to node Js and then to another API, all through HTTP calls using axios?

时光总嘲笑我的痴心妄想 提交于 2020-08-19 10:54:07
问题 Let me explain my question in detail. React UI is uploading a file using axios post by creating a form-data to Node Js API. In Node Js API, using Multer received the file. const multer = require('multer'); const upload = multer({ storage: multer.memoryStorage() }); . . . router.post('/fileUpload/:customer/', upload.single('file'), async (req, res) => { try { const result = await RequestService.sendFile( req.file, req.params.customer, ); if (result.status === 200 || 204) { } else { } } catch

本地创建cli模版

我怕爱的太早我们不能终老 提交于 2020-08-18 21:05:39
nuxt基础模版不带axios封装和基础插件引用,js-cookie等,把自己常用的项目结构作为模版,使用代码生成。 步骤 1.创建cli文件夹名称,即每次执行的命令nuxtCli 2.使用yarn init初始化项目 3.修改package.json,添加bin,指向cli.js 4.创建cli。js #!/usr/bin/env node // NODE CLI 应用入口文件必须要有这样的文件名 const path = require('path') const inquirer = require('inquirer') const fs = require('fs') var stat=fs.stat; inquirer.prompt([ { type: 'input', name: 'name', message: 'Project name?' } ]).then(anwsers => { // console.log(anwsers) // { name: 'myName' } // 根据用户回答的结果生成文件 //模板目录 const temDir = path.join(__dirname,'nuxtCli') //目标目录 const destDir = process.cwd() exists(temDir,destDir,copy) }) var copy