【发布时间】:2023-03-24 21:45:01
【问题描述】:
5 video tutorial series
Original LoopBack & React tutorial from Traversy for comparison
我已按照教程进行操作,并使其在开发中的 Cloud 9 上运行。 我不确定如何将端口设置为环境变量,因此我使用 8080 对 Cloud 9 的端口进行了硬编码。现在我正尝试在 Heroku 上运行它,但我所有的 axios 帖子都已损坏。
我想我把所有的链接都改回来了
axios.get(`http://foood-liberation-front-turtlewolfe.c9users.io:8080/api/Barrels/${barrelID}`)
到axios.get(`http://localhost:3000/api/Barrels/${barrelID}`)
但我仍然缺少一些东西,我可以在 Heroku 上编译它
https://food-liberation-frontz.herokuapp.com
但是当我点击保存链接添加一个新桶时,它坏了。
```
import React, { Component } from 'react';
import axios from 'axios';
import { Link } from 'react-router-dom';
class AddBarrel extends Component {
addBarrel(newBarrel){
console.log(newBarrel);
axios.request({
method:'post',
url:'http://foood-liberation-front-turtlewolfe.c9users.io:8080/api/Barrels',
data: newBarrel
}).then(response => {
this.props.history.push('/');
}).catch( err => console.log(err));
}
onSubmit(e){
const newBarrel = {
Name: this.refs.Name.value,
barrel_number: this.refs.barrel_number.value,
contents: this.refs.contents.value,
date_last_checked: this.refs.date_last_checked.value,
date_planted: this.refs.date_planted.value,
location: this.refs.location.value,
size: this.refs.size.value,
notes: this.refs.notes.value
}
this.addBarrel(newBarrel);
e.preventDefault();
}
render () {
return (
<div className = "container green lighten-3" >
<br />
<Link className = "btn grey" to = "/">back</Link>
<h6>add a Barrel</h6>
<form onSubmit = {this.onSubmit.bind(this)}>
<div className = "input-field" >
<input type = "text" name = "Name" ref = "Name" />
<label htmlFor = "Name" >Name</label>
</div>
<div className = "input-field" >
<input type = "text" name = "barrel_number" ref = "barrel_number" />
<label htmlFor = "barrel_number" >barrel number</label>
</div>
<div className = "input-field" >
<input type = "text" name = "contents" ref = "contents" />
<label htmlFor = "contents" >contents</label>
</div>
<div className = "input-field" >
<input type = "date" name = "date_planted" ref = "date_planted" />
<label htmlFor = "date_planted" ></label>
</div>
<div className = "input-field" >
<input type = "date" name = "date_last_checked" ref = "date_last_checked" />
<label htmlFor = "date_last_checked" ></label>
</div>
<div className = "input-field" >
<input type = "text" name = "location" ref = "location" />
<label htmlFor = "location" >location</label>
</div>
<div className = "input-field" >
<input type = "text" name = "size" ref = "size" />
<label htmlFor = "size" >size</label>
</div>
<div className = "input-field" >
<input type = "text" name = "notes" ref = "notes" />
<label htmlFor = "notes" >notes</label>
</div>
<input type = "submit" value = "Save" className = "btn" />
</form>
</div>
)
}
}
export default AddBarrel;
```
【问题讨论】:
-
github.com/TurtleWolf/Food_Liberation_Front8080 我创建了一个新的存储库,这个应该都是 localhost:8080 我之前忘记更改服务器配置。接下来,我正在安装本地版本的 Node.js。我喜欢在线开发,但调试本地构建可能更容易,我可以将其保留在:3000,我只将其更改为:8080 以在 C9 在线运行
-
我用 localhost:3000 制作了这个版本,我希望今晚在本地环境中尝试一下。 github.com/TurtleWolf/Food_Liberation_Front3000
-
这感觉很重要,这是我尝试过 react 路由器的第一个项目,几乎是第二个正在部署的主题。github.com/facebook/create-react-app/blob/master/packages/…
-
在 repo 中搜索“get”后,我想我需要在 server/server.js 中重构
-
看起来他们正在添加一个通配符来解释 React Router,但这个例子是针对 Express,而不是 LoopBack,所以我不确定我应该如何重构这部分。 !image
标签: heroku loopbackjs create-react-app cloud9