Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法在heroku服务器上获取/注册错误_Javascript_Node.js_Reactjs - Fatal编程技术网

Javascript 无法在heroku服务器上获取/注册错误

Javascript 无法在heroku服务器上获取/注册错误,javascript,node.js,reactjs,Javascript,Node.js,Reactjs,我遇到了这个问题,它给了我无法获取/注册的机会,但为什么前端的获取工作正常,而没有注册,我是不是遗漏了什么 在注册表js文件中获取时出错 日志图片 @VyasArpit 路由文件 import React from 'react'; class Register extends React.Component { constructor (props) { super(props); this.state = { email

我遇到了这个问题,它给了我无法获取/注册的机会,但为什么前端的获取工作正常,而没有注册,我是不是遗漏了什么

在注册表js文件中获取时出错

日志图片

@VyasArpit

路由文件

import React from 'react';

class Register extends React.Component  {
    constructor (props) {
        super(props);
        this.state = {
            email : '',
            password : '',
            name : ''
        }
    }
    onNameChange = (event) => {
        this.setState({name : event.target.value})
    }
    onEmailChange = (event) => {
        this.setState({email : event.target.value})
    }
    onPasswordChange = (event) => {
        this.setState({password : event.target.value})
    }
    onSubmitSignIn = () => {
        fetch(' https://dry-mesa-91343.herokuapp.com/register', {
            method : 'post',
            headers : {'Content-Type' : 'application/json'},
            body : JSON.stringify ({
                email : this.state.email,
                password : this.state.password,
                name : this.state.name
            })  
        })
            .then(response => response.json())
            .then(user => {
                if (user.id){
                    this.props.loadUser(user);
                    this.props.onRouteChange('home');
                }
            })
    }
    render () {
        return (
            <article className ="br3 ba dark-gray b--black-10 mv4 w-120 w-50-m w-25-l mw5  shadow-5 center">
                    <main className ="pa4 black-80">
                    <div className ="measure">
                    <fieldset id="sign_up" className ="ba b--transparent ph0 mh0">
                    <legend className ="f2 fw6 ph0 mh0">Register</legend>
                    <div className ="mt3">
                        <label className ="db fw6 lh-copy f6" htmlFor="name">Name</label>
                        <input 
                        className ="pa2 input-reset ba bg-transparent hover-bg-black hover-white w-100"
                         type="text" 
                         name="name" 
                          id="name"
                          onChange = {this.onNameChange}
                          />
                    </div>
                    <div className ="mt3">
                        <label className ="db fw6 lh-copy f6" htmlFor="email-address">Email</label>
                        <input 
                        className ="pa2 input-reset ba bg-transparent hover-bg-black hover-white w-100" 
                        type="email"
                         name="email-address"  
                         id="email-address"
                         onChange = {this.onEmailChange}  
                         />
                    </div>
                    <div className ="mv3">
                        <label className ="db fw6 lh-copy f6" htmlFor="password">Password</label>
                        <input 
                        className ="b pa2 input-reset ba bg-transparent hover-bg-black hover-white w-100" 
                        type="password" 
                        name="password" 
                         id="password"
                         onChange = {this.onPasswordChange}
                         />
                    </div>
                    </fieldset>
                    <div className ="">
                        <input 
                            onClick= {this.onSubmitSignIn} 
                            className ="b ph3 pv2 input-reset ba b--black bg-transparent grow pointer f6 dib"
                             type="submit" 
                             value="Register"/>
                    </div>
                </div>
             </main>
            </article>
        );
    }
}

export default Register;
从“React”导入React;
类寄存器扩展了React.Component{
建造师(道具){
超级(道具);
此.state={
电子邮件:“”,
密码:“”,
名称:“”
}
}
onNameChange=(事件)=>{
this.setState({name:event.target.value})
}
onEmailChange=(事件)=>{
this.setState({email:event.target.value})
}
onPasswordChange=(事件)=>{
this.setState({密码:event.target.value})
}
onSubmitSignIn=()=>{
取('https://dry-mesa-91343.herokuapp.com/register', {
方法:“post”,
标题:{'Content-Type':'application/json'},
正文:JSON.stringify({
电子邮件:this.state.email,
密码:this.state.password,
名称:this.state.name
})  
})
.then(response=>response.json())
。然后(用户=>{
if(user.id){
this.props.loadUser(用户);
这个.props.onRouteChange('home');
}
})
}
渲染(){
返回(
登记
名称
电子邮件
密码
);
}
}
导出默认寄存器;
@VyasArpit

路由文件

import React from 'react';

class Register extends React.Component  {
    constructor (props) {
        super(props);
        this.state = {
            email : '',
            password : '',
            name : ''
        }
    }
    onNameChange = (event) => {
        this.setState({name : event.target.value})
    }
    onEmailChange = (event) => {
        this.setState({email : event.target.value})
    }
    onPasswordChange = (event) => {
        this.setState({password : event.target.value})
    }
    onSubmitSignIn = () => {
        fetch(' https://dry-mesa-91343.herokuapp.com/register', {
            method : 'post',
            headers : {'Content-Type' : 'application/json'},
            body : JSON.stringify ({
                email : this.state.email,
                password : this.state.password,
                name : this.state.name
            })  
        })
            .then(response => response.json())
            .then(user => {
                if (user.id){
                    this.props.loadUser(user);
                    this.props.onRouteChange('home');
                }
            })
    }
    render () {
        return (
            <article className ="br3 ba dark-gray b--black-10 mv4 w-120 w-50-m w-25-l mw5  shadow-5 center">
                    <main className ="pa4 black-80">
                    <div className ="measure">
                    <fieldset id="sign_up" className ="ba b--transparent ph0 mh0">
                    <legend className ="f2 fw6 ph0 mh0">Register</legend>
                    <div className ="mt3">
                        <label className ="db fw6 lh-copy f6" htmlFor="name">Name</label>
                        <input 
                        className ="pa2 input-reset ba bg-transparent hover-bg-black hover-white w-100"
                         type="text" 
                         name="name" 
                          id="name"
                          onChange = {this.onNameChange}
                          />
                    </div>
                    <div className ="mt3">
                        <label className ="db fw6 lh-copy f6" htmlFor="email-address">Email</label>
                        <input 
                        className ="pa2 input-reset ba bg-transparent hover-bg-black hover-white w-100" 
                        type="email"
                         name="email-address"  
                         id="email-address"
                         onChange = {this.onEmailChange}  
                         />
                    </div>
                    <div className ="mv3">
                        <label className ="db fw6 lh-copy f6" htmlFor="password">Password</label>
                        <input 
                        className ="b pa2 input-reset ba bg-transparent hover-bg-black hover-white w-100" 
                        type="password" 
                        name="password" 
                         id="password"
                         onChange = {this.onPasswordChange}
                         />
                    </div>
                    </fieldset>
                    <div className ="">
                        <input 
                            onClick= {this.onSubmitSignIn} 
                            className ="b ph3 pv2 input-reset ba b--black bg-transparent grow pointer f6 dib"
                             type="submit" 
                             value="Register"/>
                    </div>
                </div>
             </main>
            </article>
        );
    }
}

export default Register;
从“React”导入React;
类寄存器扩展了React.Component{
建造师(道具){
超级(道具);
此.state={
电子邮件:“”,
密码:“”,
名称:“”
}
}
onNameChange=(事件)=>{
this.setState({name:event.target.value})
}
onEmailChange=(事件)=>{
this.setState({email:event.target.value})
}
onPasswordChange=(事件)=>{
this.setState({密码:event.target.value})
}
onSubmitSignIn=()=>{
取('https://dry-mesa-91343.herokuapp.com/register', {
方法:“post”,
标题:{'Content-Type':'application/json'},
正文:JSON.stringify({
电子邮件:this.state.email,
密码:this.state.password,
名称:this.state.name
})  
})
.then(response=>response.json())
。然后(用户=>{
if(user.id){
this.props.loadUser(用户);
这个.props.onRouteChange('home');
}
})
}
渲染(){
返回(
登记
名称
电子邮件
密码
);
}
}
导出默认寄存器;

在server.js文件中,您应该包含以下代码,以便将数据库url连接到后端:

const db= knex({
  client: 'pg',
  connection: {
    connectionString : process.env.DATABASE_URL,
    ssl: false,
});
我也有同样的问题-我无法注册新用户,直到我将ssl更改为false(你可以看这个)

来自heroku的官方教程:

就我而言,我刚刚写道:

ssl: false
如果它不起作用,试着读一下:

在server.js文件中,您应该包含以下代码,以便将数据库url连接到后端:

const db= knex({
  client: 'pg',
  connection: {
    connectionString : process.env.DATABASE_URL,
    ssl: false,
});
我也有同样的问题-我无法注册新用户,直到我将ssl更改为false(你可以看这个)

来自heroku的官方教程:

就我而言,我刚刚写道:

ssl: false
如果它不起作用,试着读一下:

您能分享您的路线文件吗?使用您定义的http方法。您可以共享您的路由文件吗?使用您定义的http方法。