当前位置:网站首页>涂鸦云开发 demo 登录
涂鸦云开发 demo 登录
2022-06-29 10:15:00 【夜跑者】
涂鸦Iot 云开发平台提供了 前后端demo,
前端demo地址:
git clone https://github.com/tuya/iot-portal.git后端demo地址:
https://github.com/tuya/iot-server.git此demo采用微前端框架qiankun,react框架来开发的。前端要配置代理访问后端接口,前端demo中配置代理如下:
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app, opts = {}) {
const apiPath = opts.apiPath || '/api';
const target = 'http://localhost:8080/';
app.use(
apiPath,
createProxyMiddleware(Object.assign({
// see more: https://github.com/chimurai/http-proxy-middleware#options
target,
changeOrigin: true,
headers: {},
}, opts)),
);
}
后端demo跑到本地8080端口上(http://localhost:8080/),如果请求路径带有/api 则代理到后端demo服务上。这个前端demo 直接用express起的服务。如果我们采用vue框架怎么配置此代理呢?
用vue-cli创建的项目,直接在根目录创建vue.config.js即可,并配置devServer,如下所示:
module.exports = {
chainWebpack: (config) => {
config.plugin("html").tap((args) => {
args[0].title = "管理平台";
return args;
});
},
devServer: {
port: '8085',
proxy: {
"/api": {
target: "http://localhost:8080/",
changOrigin: true,
},
},
},
};
配置后,启动项目请求接口:
import { apiService } from "@tuya/connector";
apiService
.multiLogin({
userName: _mailForm.address,
pwd: _mailForm.mailSecret,
})
.then((userToken) => {
this.afterLogin(userToken, _mailForm.address)
})报了404错误,看着请求接口路径并没有/api 而是http://localhost:8085/login
应该为http://localhost:8085/api/login
原来没有配置baseUrl导致的,加上此配置接口请求成功:
import { configMethod } from '@tuya/connector';
const init = () => {
const msgWhiteList = [];
configMethod.initGlobalConfig({
headers: {
'Accept-Language': 'zh-CN'
},
baseURL: '/api',
onError: (errorObj) => {
const { code, apiMethodName } = errorObj;
if (code === '1010' || code === '111') {
localStorage.removeItem('_USERNAME');
localStorage.removeItem('_UID');
localStorage.removeItem('_ROLE_TYPE');
if (window.location.pathname !== '/login') {
window.location.replace('/login');
}
return;
}
// 需屏蔽的方法
if (msgWhiteList.includes(apiMethodName)) {
return;
}
},
});
};
export default init;
边栏推荐
- Numeric Keypad
- The use of variables in shell that you have to be familiar with
- Shell 中你不得不熟知的变量运用
- 9 easy to use JSON processing tools, greatly improving efficiency!
- 第12周实验---基于FPGA的VGA协议实现
- 【NLP】文本生成专题1:基础知识
- 嵌入式驱动开发之uboot---uboot 中的常见命令参数参数
- Recommended embedded learning books [easy to understand]
- csdn涨薪秘籍之腾讯自动化软件测试面试题(含答案)
- UserWarning: Usage of dash-separated ‘script-dir‘ will not be supported in future versions. note
猜你喜欢

什么?漫画居然能免费看全本了,这还不学起来一起做省钱小能手

BS-GX-018 基于SSM实现在校学生考试系统

Easydss is deployed on Disk C, and the video playback cannot be played normally. How to solve this problem?

csdn涨薪秘籍之腾讯自动化软件测试面试题(含答案)

Interview questions of Tencent automation software test of CSDN salary increase secret script (including answers)

极限导论总结

He was in '98. I can't play with him

Ikvm Net project progress

ModbusTCP协议WIFI无线学习型单路红外模块(小壳版)

EasyDSS部署在C盘,录像回看无法正常播放该如何解决?
随机推荐
(JS)isNaN()方法判断undefined为true的原因
[FreeRTOS] 08 mutex semaphores and priority inversion
学习通否认 QQ 号被盗与其有关:已报案;iPhone 14 量产工作就绪:四款齐发;简洁优雅的软件早已是明日黄花|极客头条...
TTL serial port learning infrared remote control module can be extended to network control
极限导论总结
csdn涨薪秘籍之腾讯自动化软件测试面试题(含答案)
Spark - Task 与 Partition 一一对应与参数详解
(JS)数组排平(flat)
加密市场接连爆雷,Celsius能避免破产吗?
Pytorch learning notes (6) -- source code analysis of dataloader
基于支持向量机的手写数字识别详解(MATLAB GUI代码,提供手写板)
The necessary operation for those big guys to fly 666 inadvertently at the bash command line terminal
UserWarning: Usage of dash-separated ‘script-dir‘ will not be supported in future versions. note
“AI x 科学计算”进行时,华为昇思 MindSpore 赛题火热开启,等你来!
The last 48 hours! The cloud XR theme competition invites you to bloom together. See you at the competition!
Modbustcp protocol WiFi wireless learning single channel infrared module (round shell version)
毕业季·进击的技术er - 职场打工人
(JS)手写深拷贝
MySQL get table information
Online sql to htmltable tool