I have a website here: http://35.221.40.223/ and a database through that: http://35.221.40.223/api/list. To post, I have http://35.221.40.223/api/addtimes. When I try to post things, its giving me a 502 error. I had the e2-micro machine type originally, so I changed it to e2-small and then e2-medium and I'm still getting the same exact error. I'm wondering if I need to continue to increase the machine type of if there is something else wrong.
Here is where I am trying to post: util.js
import "isomorphic-fetch"
export function addTime(name,time) {
return fetch('http://35.221.40.223/api/addtime', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name, time })
})
}
/etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location /api {
proxy_pass http://localhost:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_connect_timeout 240;
proxy_send_timeout 240;
proxy_read_timeout 240;
send_timeout 240;
}
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
App.js
import React from 'react';
import { addTime } from "./util";
function App() {
const [name, setName] = React.useState("")
const [time, setTime] = React.useState("")
function handleUpdate(evt) {
setName(evt.target.value);
}
function handleUpdateTime(evt) {
setTime(evt.target.value);
}
async function handleAddTime(evt) {
await addTime(name,time);
}
return <div>
<p><input type='text' value={time} onChange={handleUpdateTime} /></p>
<p><input type='text' value={name} onChange={handleUpdate} /></p>
<button className='button-style' onClick={handleAddTime}>Add Time</button>
</div>
}
export default App;
Another other code y'all think might be useful I would be happy to provide.
Edit: I changed util.js and am receiving the same result.
import "isomorphic-fetch"
export function addTime(name,time) {
return fetch('http://35.221.40.223/api/addtime?name=${name}&time=${time}', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name, time })
})
}
question from:
https://stackoverflow.com/questions/65892136/connecting-my-database-to-my-website-on-google-cloud-platform 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…