我正在使用Axios从客户端向Express.js服务器发送请求.
我在客户端设置了一个cookie,我想从所有Axios请求中读取该cookie,而不是手动添加它们来手动请求.
这是我的客户端请求示例:
axios.get(`some api url`).then(response => ...
Run Code Online (Sandbox Code Playgroud)
我试图通过在Express.js服务器中使用这些属性来访问标头或cookie:
req.headers
req.cookies
Run Code Online (Sandbox Code Playgroud)
它们都不包含任何cookie.我正在使用cookie解析器中间件:
app.use(cookieParser())
Run Code Online (Sandbox Code Playgroud)
如何让Axios自动在请求中发送cookie?
编辑:
我在客户端设置cookie如下:
import cookieClient from 'react-cookie'
...
let cookie = cookieClient.load('cookie-name')
if(cookie === undefined){
axios.get('path/to/my/cookie/api').then(response => {
if(response.status == 200){
cookieClient.save('cookie-name', response.data, {path:'/'})
}
})
}
...
Run Code Online (Sandbox Code Playgroud)
虽然它也使用Axios,但它与问题无关.一旦设置了cookie,我只想在我的所有请求中嵌入cookie.
即使tho模块已安装且存在,Flow无法解析它并引发错误.请参阅下面:1)在bash内部运行flow,它会抛出错误,找不到模块
user@pc:~/code/project$ flow
Error ????????????????????????????????? src/functionalities/Growth/index.js:3:25
Cannot resolve module react-redux.
1? // @flow
2? import React from "react"
3? import { connect } from "react-redux"
4?
5? type Props = {
6? children: Function
Found 1 error
Run Code Online (Sandbox Code Playgroud)
2)下面的命令检查目录是否存在,确实存在
user@pc:~/code/project$ ls node_modules | grep react-redux
react-redux
Run Code Online (Sandbox Code Playgroud)
我试图删除并重新安装node_modules目录和yarn.lock文件.
版本应匹配:
flow version
Flow, a static type checker for JavaScript, version 0.77.0
Run Code Online (Sandbox Code Playgroud)
.flowconfig:
[version]
0.77.0
Run Code Online (Sandbox Code Playgroud)
这很可能是Flow的错误,我也提交了问题.
从数组中删除与特定字符串匹配的所有元素的最简单方法是什么?例如:
array = [1,2,'deleted',4,5,'deleted',6,7];
我想'deleted'从数组中删除所有.
我刚开始使用React.js,我无法导入组件.
我有这个结构,如本教程(YouTube链接)所示:
-- src
----| index.html
----| app
------| index.js
------| components
--------| MyCompontent.js
Run Code Online (Sandbox Code Playgroud)
这是我的index.js:
import React from 'react';
import { render } from 'react-dom';
import { MyCompontent } from "./components/MyCompontent";
class App extends React.Component {
render() {
return (
<div>
<h1>Foo</h1>
<MyCompontent/>
</div>
);
}
}
render(<App />, window.document.getElementById('app'));
Run Code Online (Sandbox Code Playgroud)
这是MyComponent.js:
import React from "react";
export class MyCompontent extends React.Component {
render(){
return(
<div>MyCompontent</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用这个webpack文件(GitHub链接).
但是,当我运行它时,我的模块无法加载.
我在浏览器控制台中收到此错误:
错误:找不到模块"./components/MyCompontent"
[WDS] …Run Code Online (Sandbox Code Playgroud) 我正在按照本教程https://www.railstutorial.org/book/static_pages#sec-sample_app_setup成功完成所有步骤(git commit和push on github,heroku login和heroku app creation),直到这个命令为止:
$ git push heroku master
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
$ git push heroku origin
$ git push heroku
Run Code Online (Sandbox Code Playgroud)
它导致了这个错误:
> fatal: No path specified. See 'man git-pull' for valid url syntax
Run Code Online (Sandbox Code Playgroud)
我尝试通过遵循这个答案解决它,但它对我不起作用.
在我尝试了最佳答案之后,这是我在.git中的配置文件:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = https://github.com/kunokdev/sample_app.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[remote "heroku"]
url = https://git.heroku.com/test774.git
fetch = +refs/heads/*:refs/remotes/heroku/*
Run Code Online (Sandbox Code Playgroud)
有什么想法是什么问题?我正在使用Ubuntu 14.04操作系统. …
我在 NPM 上有一个包,它使用 React 版本 15 作为对等依赖项。但是,我希望它停止向升级其 React 版本的用户发出警告。如何使包同时支持版本 15 和 16?
"peerDependencies": {
"react-dom": "^15.0.0"
},
Run Code Online (Sandbox Code Playgroud)
处理这些问题最方便的方法是什么?
是否"*15.0.0"足够好?
我有JSON代码:
{ "time":"2015-10-20T11:20:00+02:00" }
Run Code Online (Sandbox Code Playgroud)
我从我的脚本中读到了JSON,表中的输出是:
2015-10-20T11:20:00+02:00
Run Code Online (Sandbox Code Playgroud)
但是我希望输出等于那天和它的时间.
例如:星期二20:00(如果我的时区是+02)
我有一个方法从FTP服务器下载文件,它可以在较小的文件上正常工作,但是当我用它来下载~5GB大小的zip类型的文件时,它会下载它,但之后它什么也没做.当它达到下载的100%时,脚本不会继续.我是否应该等待下载完成后在后台实际执行某些操作?有文件大小限制吗?
const FTP = require('ftp')
Run Code Online (Sandbox Code Playgroud)
可以在npm找到
downloadFile: params => {
return new Promise((resolve, reject) => {
let ftpClient = new FTP()
let total = params.state.fileSize
let progress = 0
ftpClient.on('ready', _ => {
console.log(`Downloading ${params.targetedFile} ...`);
ftpClient.get(params.targetedFile, (err, stream) => {
if (err) reject(err)
stream.on('data', buffer => {
progress += buffer.length
process.stdout.write(`Progress: ${(progress/total*100).toFixed(2)}% (${progress}/${total}) \r`)
})
stream.once('close', _ => {
ftpClient.end()
console.log(`Saved downloaded file to ${params.localDir}`);
resolve(params.localDir)
})
stream.pipe(fs.createWriteStream(params.localDir))
})
})
ftpClient.connect(params.auth)
})
}
Run Code Online (Sandbox Code Playgroud)
基本上,stream.once('close', ...)下载大文件时不会执行回调.并且它会针对相同类型的较小文件执行.
当我在localhost Ubuntu 14.04(LAMP)上运行我的CakePHP应用程序时出现此错误:
警告:_cake_core_ cache无法在第328行的/var/www/html/tmc/lib/Cake/Cache/Cache.php中将'cake_dev_en-us'写入文件缓存
警告:/ var/www/html/tmc/app/tmp/cache/persistent /在第385行的/var/www/html/tmc/lib/Cake/Cache/Engine/FileEngine.php中无法写入
致命错误:没有正确配置消息'Cache engine"_ cake_core_"的未捕获异常'CacheException'.确保在/var/www/html/tmc/lib/Cake/Cache/Cache.php:186中安装了所需的扩展,并且凭据/权限是正确的.堆栈跟踪:#0/var/www/html/tmc/lib/Cake/Cache/Cache.php(151):Cache :: _ buildEngine('_ cake_core_')#1 /var/www/html/tmc/app/Config/core.php(386):Cache :: config('_ cake_core_' ,数组)#2 /var/www/html/tmc/lib/Cake/Core/Configure.php(72):include('/ var/www/html/t ...')#3/var/www/html/tmc/lib/Cake/bootstrap.php(431):Configure :: bootstrap(true)#4 /var/www/html/tmc/app/webroot/index.php(97):include('/ var/www/html/t ...')在第186行的/var/www/html/tmc/lib/Cake/Cache/Cache.php中抛出#5 {main}
我不知道问题出在哪里.我试过sudo chmod 775 /var/www/html/tmc/lib/Cake/Cache/Engine/FileEngine.php命令,但它没有解决问题.
我通过终端命令生成(烘焙)控制器:
bin/cake bake.bake controller [controller_name]
有没有命令可以逆转它?删除生成的控制器?
javascript ×7
cakephp ×2
node.js ×2
axios ×1
cakephp-3.0 ×1
cakephp-bake ×1
cookies ×1
dependencies ×1
express ×1
flowtype ×1
ftp-client ×1
git ×1
heroku ×1
json ×1
lamp ×1
npm ×1
react-redux ×1
reactjs ×1
ubuntu ×1
webpack ×1