I know this question has been asked, but I still haven't been able to figure this out. Been working on it for three days trying to solve this.
I built this app and it worked fine on my local machine, but after I deployed the back end on Heroku the register endpoint is getting an error, but I don't know what the actual problem is. All I am getting in the console is POST https://whispering-inlet-63830.herokuapp.com/register 400 (Bad Request) and when I click on it it brings me to the fetch statement on the front end.
I know the front end is talking to the back end because in the network tab of chrome tools it has the message ”Unable to register” which I put in a catch statement in case of an error.
Finally, I am using the Heroku Postgres add-on. I have created two tables that take are supposed to store the info in the req.body that is received by the back end.
EXPECTED RESULT:
Be able to register a user
ACTUAL RESULT:
getting 400 bad request error, but not sure how to further debug it and pinpoint the issue
ACTIONS TAKEN:
Double checked all dependancies and proper configuration
Triple checked that the URL in the fetch statement was correct
Double checked that I have these two lines in accordance with
Double checked postgres table configuration
Heroku Documentation
connectionString: process.env.DATABASE_URL,
ssl: true
Register.js (front-end):
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://whispering-inlet-63830.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(res => res.json())
.then(user => {
if (user.id) {
this.props.loadUser(user);
this.props.onRouteChange('home');
}
})
}
render() {
return (
<article className="br3 ba b--black-10 mv4 w-100 w-50-m w-25-l mw6 shadow-5 center">
<main className="pa4 black-80">
<div className="measure">
<fieldset id="sign_up" className="ba b--transparent ph0 mh0">
<legend className="f1 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;
server.js (back-end):
const express = require('express');
const bodyParser = require('body-parser');
const bcrypt = require('bcrypt-nodejs');
const cors = require('cors');
const knex = require('knex');
/***** ENDPOINT CONTROLLERS *****/
const register = require('./controllers/register');
const signin = require('./controllers/signin');
const profile = require('./controllers/profile');
const image = require('./controllers/image');
/***** ENDPOINT CONTROLLERS *****/
const db = knex({
client: 'pg',
connection: {
connectionString: process.env.DATABASE_URL,
ssl: true
}
});
const app = express();
const PORT = process.env.PORT || 3000;
app.use(bodyParser.json());
app.use(cors());
app.get('/', (req, res) => { res.send('success') })
app.post('/signin', (req, res) => { signin.handleSignin(req, res, db, bcrypt) })
app.post('/register', (req, res) => { register.handleRegister(req, res, db, bcrypt) })
app.get('/profile/:id', (req, res) => { profile.handleProfileGet(req, res, db)})
app.put('/image', (req, res) => {image.handleImage(req, res, db)})
app.post('/imageurl', (req, res) => {image.handleApiCall(req, res)})
app.listen(PORT, () =>{
console.log(`app is running on port ${PORT}`);
})
register.js (back-end):
const handleRegister = (req, res, db, bcrypt) => {
const { email, name, password } = req.body;
if (!email || !name || !password) {
return res.status(400).json('Incorrect form submission');
}
const hash = bcrypt.hashSync(password);
db.transaction(trx => {
trx.insert({
hash: hash,
email: email
})
.into('login')
.returning('email')
.then(loginEmail => {
return trx('users')
.returning('*')
.insert({
email: loginEmail[0].email,
name: name,
joined: new Date()
})
.then(user => {
res.json(user[0]);
})
})
.then(trx.commit)
.catch(trx.rollback)
})
.catch(err => res.status(400).json('Unable to register').console.log('This is the error --> ', err))
}
module.exports = {
handleRegister: handleRegister
};
Heroku Logs:
2023-02-16T21:07:39.838345+00:00 heroku[web.1]: Cycling
2023-02-16T21:07:39.854981+00:00 heroku[web.1]: State changed from up to starting
2023-02-16T21:07:41.764756+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2023-02-16T21:07:42.090509+00:00 heroku[web.1]: Process exited with status 143
2023-02-16T21:07:42.511393+00:00 heroku[web.1]: Starting process with command `npm start`
2023-02-16T21:07:44.853939+00:00 app[web.1]:
2023-02-16T21:07:44.853974+00:00 app[web.1]: > brain-box-api#1.0.0 start
2023-02-16T21:07:44.853975+00:00 app[web.1]: > node server.js
2023-02-16T21:07:44.853975+00:00 app[web.1]:
2023-02-16T21:07:45.163380+00:00 app[web.1]: app is running on port 25098
2023-02-16T21:07:45.364101+00:00 heroku[web.1]: State changed from starting to up
2023-02-16T22:02:53.616299+00:00 heroku[router]: at=info method=GET path="/" host=whispering-inlet-63830.herokuapp.com request_id=3a0cf964-1bff-497c-bad8-6a32e8a1909f fwd="72.200.93.242" dyno=web.1 connect=0ms service=6ms status=304 bytes=181 protocol=https
2023-02-17T18:47:53.733408+00:00 heroku[router]: at=info method=OPTIONS path="/register" host=whispering-inlet-63830.herokuapp.com request_id=4000b4f6-dfbb-4f58-92ba-d4e7f5c4794e fwd="72.200.93.242" dyno=web.1 connect=0ms service=79ms status=204 bytes=301 protocol=https
2023-02-17T18:47:54.189603+00:00 heroku[router]: at=info method=POST path="/register" host=whispering-inlet-63830.herokuapp.com request_id=20bf2c7b-8a82-485a-b4f5-c6658b09a4c5 fwd="72.200.93.242" dyno=web.1 connect=0ms service=372ms status=400 bytes=268 protocol=https
2023-02-17T19:02:16.261886+00:00 heroku[router]: at=info method=GET path="/register" host=whispering-inlet-63830.herokuapp.com request_id=d5c31a99-7fcb-479f-a54c-1100b5017ba6 fwd="35.196.132.85" dyno=web.1 connect=0ms service=2ms status=404 bytes=423 protocol=https
2023-02-17T19:02:50.970631+00:00 heroku[router]: at=info method=GET path="/register" host=whispering-inlet-63830.herokuapp.com request_id=d93092e0-b564-45c8-8cdc-fe2ca278fa07 fwd="35.237.4.214" dyno=web.1 connect=0ms service=1ms status=404 bytes=423 protocol=https
2023-02-17T20:13:45.694986+00:00 heroku[router]: at=info method=OPTIONS path="/register" host=whispering-inlet-63830.herokuapp.com request_id=85c6f70d-b67f-4f65-a062-90a323f66b44 fwd="72.200.93.242" dyno=web.1 connect=0ms service=1ms status=204 bytes=301 protocol=https
2023-02-17T20:13:46.021015+00:00 heroku[router]: at=info method=POST path="/register" host=whispering-inlet-63830.herokuapp.com request_id=69e09db1-415e-401e-a8ab-f0cd0d38df3c fwd="72.200.93.242" dyno=web.1 connect=0ms service=242ms status=400 bytes=268 protocol=https
2023-02-17T20:17:09.986066+00:00 heroku[router]: at=info method=OPTIONS path="/signin" host=whispering-inlet-63830.herokuapp.com request_id=f2069f6f-b316-4e6f-b85b-a74255b1466f fwd="72.200.93.242" dyno=web.1 connect=0ms service=1ms status=204 bytes=301 protocol=https
2023-02-17T20:17:10.073676+00:00 heroku[router]: at=info method=POST path="/signin" host=whispering-inlet-63830.herokuapp.com request_id=f86c958b-77af-449d-b223-8270f96953fc fwd="72.200.93.242" dyno=web.1 connect=0ms service=4ms status=400 bytes=267 protocol=https
2023-02-17T20:20:10.278343+00:00 heroku[router]: at=info method=GET path="/register" host=whispering-inlet-63830.herokuapp.com request_id=87a20845-ad6f-415b-b550-4d08f3679d6a fwd="35.196.132.85" dyno=web.1 connect=0ms service=1ms status=404 bytes=423 protocol=https
2023-02-17T20:23:34.918082+00:00 heroku[router]: at=info method=GET path="/register" host=whispering-inlet-63830.herokuapp.com request_id=8fdfcde2-31c0-4eac-9b88-ff1a24741917 fwd="35.227.62.178" dyno=web.1 connect=0ms service=1ms status=404 bytes=423 protocol=https
2023-02-17T20:30:30.994860+00:00 heroku[router]: at=info method=GET path="/register" host=whispering-inlet-63830.herokuapp.com request_id=8f2a9526-098b-40d4-b053-6e557ec47e00 fwd="98.145.195.210" dyno=web.1 connect=0ms service=1ms status=404 bytes=423 protocol=https
2023-02-17T20:30:35.366735+00:00 heroku[router]: at=info method=GET path="/" host=whispering-inlet-63830.herokuapp.com request_id=9727e353-da90-412e-bd60-9fb83df7adbd fwd="98.145.195.210" dyno=web.1 connect=0ms service=2ms status=200 bytes=237 protocol=https
2023-02-17T20:30:35.500222+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=whispering-inlet-63830.herokuapp.com request_id=166f4026-99a5-488e-8b01-0032e9ef9e58 fwd="98.145.195.210" dyno=web.1 connect=0ms service=1ms status=404 bytes=426 protocol=https
2023-02-17T20:38:32.722970+00:00 heroku[router]: at=info method=GET path="/" host=whispering-inlet-63830.herokuapp.com request_id=ceaaf3e6-7250-4a81-9414-3c3efcc70d84 fwd="98.145.195.210" dyno=web.1 connect=0ms service=1ms status=200 bytes=237 protocol=https
2023-02-17T20:39:24.076167+00:00 heroku[router]: at=info method=OPTIONS path="/register" host=whispering-inlet-63830.herokuapp.com request_id=9cc8dde8-310b-4995-8c0f-719c7a0fbe43 fwd="72.200.93.242" dyno=web.1 connect=0ms service=0ms status=204 bytes=301 protocol=https
2023-02-17T20:39:24.403949+00:00 heroku[router]: at=info method=POST path="/register" host=whispering-inlet-63830.herokuapp.com request_id=47d82db6-d90a-469a-916a-7f7a3493bea8 fwd="72.200.93.242" dyno=web.1 connect=0ms service=243ms status=400 bytes=268 protocol=https
2023-02-17T20:40:25.768482+00:00 heroku[router]: at=info method=POST path="/register" host=whispering-inlet-63830.herokuapp.com request_id=1bd617a6-708c-42f5-b44c-7fd9a64e92e8 fwd="98.145.195.210" dyno=web.1 connect=0ms service=244ms status=400 bytes=268 protocol=https
Related
I'm working on nodejs/Parse server it works fine on localy but when I tried to deploy my server to heroku I found that the dashboard didn't load the DB data (dasboard display loading spinner untel bring Time out). like this:
here is my server dashboard instance:
let dashboard = new ParseDashboard({
apps: [
{
appName: env.PARSE_APPNAME,
appId: env.PARSE_APPID',
masterKey: env.PARSE_MASTERKEY,
clientKey: env.PARSE_CLIENTKEY,
javascriptKey: env.PARSE_JAVASCRIPTKEY,
restApiKey: env.PARSE_RESTAPIKEY,
graphQLServerURL: `${host}:${port}${mountPathGraphQL}`,//
serverURL: `${host}:${port}${mountPath}`,//
iconName: env.DASH_ICON || "logo.png"
},
],
iconsFolder: "icons",
users: [
{
user: env.DASH_USER,
pass: env.DASH_PASS'
}
]
}, { allowInsecureHTTP: true });
and api call:
let mountPathDash = env.PARSE_MOUNT_DASH || '/dashboard'
app.use(mountPathDash, dashboard);
I have also prepared Procfile file contains:
web: node server.js
on my heroku log:
2021-02-22T14:17:23.931913+00:00 heroku[router]: at=info method=GET
path="/dashboard/" host=nplboost.herokuapp.com
request_id=c4244237-7d6a-4886-9f8e-c7190e9846ed fwd="196.203.182.5"
dyno=web.1 connect=1ms service=3ms status=200 bytes=712 protocol=https
2021-02-22T14:17:25.273889+00:00 heroku[router]: at=info method=GET
path="/dashboard/bundles/dashboard.bundle.js"
host=nplboost.herokuapp.com
request_id=97de1799-19e7-43c8-856c-e22383a7c645 fwd="196.203.182.5"
dyno=web.1 connect=0ms service=6ms status=304 bytes=239 protocol=https
2021-02-22T14:17:25.664996+00:00 heroku[router]: at=info method=GET
path="/dashboard/parse-dashboard-config.json"
host=nplboost.herokuapp.com
request_id=f220e66b-af01-4169-98f3-28c06f369859 fwd="196.203.182.5"
dyno=web.1 connect=6ms service=3ms status=304 bytes=151 protocol=https
2021-02-22T14:31:29.918524+00:00 heroku[router]: at=info method=GET
path="/dashboard/apps/NplBoost/migrations" host=nplboost.herokuapp.com
request_id=a2da7714-0752-48dd-a1a3-4fb0dc2f1047 fwd="196.203.182.5"
dyno=web.1 connect=1ms service=16ms status=200 bytes=712
protocol=https 2021-02-22T14:31:29.922030+00:00 heroku[router]:
at=info method=GET path="/dashboard/bundles/sprites.svg"
host=nplboost.herokuapp.com
request_id=ea1e7dde-2270-47c6-8335-410808724bec fwd="196.203.182.5"
dyno=web.1 connect=3ms service=12ms status=304 bytes=238
protocol=https 2021-02-22T14:31:29.922877+00:00 heroku[router]:
at=info method=GET path="/dashboard/" host=nplboost.herokuapp.com
request_id=88a0e442-734a-4885-95e7-9d0c3cb00c41 fwd="196.203.182.5"
dyno=web.1 connect=2ms service=17ms status=304 bytes=168
protocol=https 2021-02-22T14:31:29.930207+00:00 heroku[router]:
at=info method=GET path="/dashboard/appicons/logo.png"
host=nplboost.herokuapp.com
request_id=1dec56f5-683c-4cef-a800-81061eb0b56b fwd="196.203.182.5"
dyno=web.1 connect=2ms service=21ms status=200 bytes=18008
protocol=https
My parse configuration:
var parseServer = new ParseServer({
cloud: __dirname + '/cloud/main.js',
databaseURI: databaseUri,
appName: env.PARSE_APPNAME,
appId: env.PARSE_APPID,
masterKey: env.PARSE_MASTERKEY,
clientKey: env.PARSE_CLIENTKEY,
javascriptKey: env.PARSE_JAVASCRIPTKEY,
restApiKey: env.PARSE_RESTAPIKEY,
fileKey: env.PARSE_FILEKEY,
webhookKey: env.PARSE_WEBHOOKKEY,
dotNetKey: env.PARSE_DOTNETKEY,
serverURL: `${host}:${port}${mountPath}`,
publicServerURL: `${host}:${port}${mountPath}`,
verifyUserEmails: false,
emailVerifyTokenValidityDuration: 24 * 60 * 60,
preventLoginWithUnverifiedEmail: false,
emailAdapter: !hasSMTPInfo ? undefined : {
module: 'parse-smtp-template',
options: {
port: env.EMAIL_PORT,
host: env.EMAIL_HOST,
user: env.EMAIL_USER,
password: env.EMAIL_PASSWORD,
fromAddress: env.EMAIL_FROMADDRESS,
template: env.EMAIL_TEMPLATE,
templatePath: env.EMAIL_TEMPLATEPATH
}
},
accountLockout: {
duration: 10, // threshold policy setting determines the number of failed sign-in attempts that will cause a user account to be locked. Set it to an integer value greater than 0 and less than 1000.
threshold: 6, // duration policy setting determines the number of minutes that a locked-out account remains locked out before automatically becoming unlocked. Set it to a value greater than 0 and less than 100000.
},
passwordPolicy: {
validatorPattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.{8,})/, // enforce password with at least 8 char with at least 1 lower case, 1 upper case and 1 digit
//validatorCallback: (password) => { return validatePassword(password) },
validationError: 'Password must contain at least 8 chars, 1 lowercase, 1 lowercase and 1 digit.', // optional error message to be sent instead of the default "Password does not meet the Password Policy requirements." message.
doNotAllowUsername: true, // optional setting to disallow username in passwords
maxPasswordAge: 90, // optional setting in days for password expiry. Login fails if user does not reset the password within this period after signup/last reset.
maxPasswordHistory: 5, // optional setting to prevent reuse of previous n passwords. Maximum value that can be specified is 20. Not specifying it or specifying 0 will not enforce history.
resetTokenValidityDuration: 24 * 60 * 60, // expire after 24 hours
},
});
with my Server URL is nplboost.herokuapp.com:xxxx/parse
I have recently tried to deploy my ecommerce store to Heroku.
The app is appearing however none of the information is displaying. I can't use the sign in function either I'm getting a status code 401.
Everything appears fine in the localhost.
Im using MongoDB Atlas to host the database.
I've posted the config var to heroku using the following command heroku config:set MONGODB_URL="mongodb+srv://yourUsername:yourPassword#yourClusterName.n9z04.mongodb.net/sample_mflix?retryWrites=true&w=majority" with the relevant information with the relevant information.
Is there a step that I am missing. Should I put the config var somewhere in my source code?
I've also attached the heroku log incase it has some relevant information in it.
2021-01-01T10:24:18.348137+00:00 app[web.1]: Server started at
http://localhost:5000
2021-01-01T10:24:18.896898+00:00 heroku[web.1]: State changed from starting
to up
2021-01-01T10:24:30.623315+00:00 heroku[router]: at=info method=GET path="/"
host=honeyman-designs.herokuapp.com request_id=7a2539dc-bb3e-4b8d-b77
5-4544b2977c8a fwd="79.97.31.121" dyno=web.1 connect=0ms service=30ms
status=200 bytes=2506 protocol=https
2021-01-01T10:24:30.791922+00:00 heroku[router]: at=info method=GET
path="/static/css/main.5ec8a089.chunk.css" host=honeyman-
designs.herokuapp.com
request_id=af0fde90-8dbb-4102-ad96-f5e05c44fced fwd="79.97.31.121" dyno=web.1
connect=0ms service=8ms status=200 bytes=6148 protocol=https
2021-01-01T10:24:30.796204+00:00 heroku[router]: at=info method=GET
path="/static/js/main.8623e411.chunk.js" host=honeyman-designs.herokuapp.com
r
equest_id=f4bc8514-2dde-479b-8934-8f59056ef1cd fwd="79.97.31.121" dyno=web.1
connect=1ms service=9ms status=200 bytes=43300 protocol=https
2021-01-01T10:24:30.918639+00:00 heroku[router]: at=info method=GET
path="/static/js/2.8114b5af.chunk.js" host=honeyman-designs.herokuapp.com
requ
est_id=bcc9933f-20a5-4f55-855d-6f3d5ed38886 fwd="79.97.31.121" dyno=web.1
connect=0ms service=13ms status=200 bytes=198152 protocol=https
2021-01-01T10:24:18.348137+00:00 app[web.1]: Server started at
http://localhost:5000
2021-01-01T10:24:18.896898+00:00 heroku[web.1]: State changed from starting
to up
2021-01-01T10:24:30.623315+00:00 heroku[router]: at=info method=GET path="/"
host=honeyman-designs.herokuapp.com request_id=7a2539dc-bb3e-4b8d-b77
5-4544b2977c8a fwd="79.97.31.121" dyno=web.1 connect=0ms service=30ms
status=200 bytes=2506 protocol=https
2021-01-01T10:24:30.791922+00:00 heroku[router]: at=info method=GET
path="/static/css/main.5ec8a089.chunk.css" host=honeyman-
designs.herokuapp.com
request_id=af0fde90-8dbb-4102-ad96-f5e05c44fced fwd="79.97.31.121" dyno=web.1
connect=0ms service=8ms status=200 bytes=6148 protocol=https
2021-01-01T10:24:30.796204+00:00 heroku[router]: at=info method=GET
path="/static/js/main.8623e411.chunk.js" host=honeyman-designs.herokuapp.com
r
equest_id=f4bc8514-2dde-479b-8934-8f59056ef1cd fwd="79.97.31.121" dyno=web.1
connect=1ms service=9ms status=200 bytes=43300 protocol=https
2021-01-01T10:24:30.918639+00:00 heroku[router]: at=info method=GET
path="/static/js/2.8114b5af.chunk.js" host=honeyman-designs.herokuapp.com
requ
est_id=bcc9933f-20a5-4f55-855d-6f3d5ed38886 fwd="79.97.31.121" dyno=web.1
connect=0ms service=13ms status=200 bytes=198152 protocol=https
I've used heroku ps:scale web=1 to check if any dyno's are working and they are I get this message: Scaling dynos... done, now running web at 1:Free
config.js
import dotenv from 'dotenv';
dotenv.config();
export default {
PORT: process.env.PORT || 5000,
MONGODB_URL: process.env.MONGODB_URL || 'mongodb://localhost/honeymandesigns',
}
.env file
MONGODB_URL=mongodb://localhost/honeymandesigns
server.js
const mongodbUrl = config.MONGODB_URL;
mongoose.connect(mongodbUrl, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true
}).catch(error => console.log(error.reason));
Just posting as I found the solution to my problem.
The MongoDb Atlas was connected however the data was not migrated to MongoDB atlas.
Once I migrated the data using MongoDB compass to MongoDB Atlas the data then displayed.
I followed along this youtube video to do this:
https://www.youtube.com/watch?v=tpz-6Trd1UI&t=12s
Yes,you should have an .env(https://ibb.co/j5kJznb), inside the .env file use
DB_CONNECT = mongodb+srv://username:password#cluster0.n0n6r.mongodb.net/test?retryWrites=true&w=majority
In your index.js require dotenv(https://ibb.co/C2gxk36)
const dotenv = require("dotenv");
dotenv.config();
Also,connect your database in heroku aswell https://dev.to/cpclark360/how-to-host-a-restful-node-js-server-with-mongodb-atlas-database-on-heroku-1opl
so I have an express API. Post request sent to it works locally, but when I deployed it to Heroku, it failed when I tested with Postman. Here I will show you what I get from heroku logs and my server, route code:
## Heroku logs
2020-06-28T17:00:26.000169+00:00 app[api]: Release v4 created by user
2020-06-28T17:00:26.165056+00:00 heroku[web.1]: State changed from crashed to starting
2020-06-28T17:00:27.000000+00:00 app[api]: Build succeeded
2020-06-28T17:00:28.324211+00:00 heroku[web.1]: Starting process with command `npm start`
2020-06-28T17:00:30.918283+00:00 app[web.1]:
2020-06-28T17:00:30.918309+00:00 app[web.1]: > myapp#1.0.0 start /app
2020-06-28T17:00:30.918310+00:00 app[web.1]: > node server.js
2020-06-28T17:00:30.918310+00:00 app[web.1]:
2020-06-28T17:00:32.474593+00:00 heroku[web.1]: State changed from starting to up
2020-06-28T17:01:01.738558+00:00 app[web.1]: connect succesfully!
2020-06-28T17:01:31.772725+00:00 heroku[router]: at=info method=GET path="/" host=peaceful-sierra-47869.herokuapp.com request_id=223793a6-f77d-4a2b-83bf-0c73ab117775 fwd="75.71.7.56" dyno=web.1 connect=1ms service=12ms status=404 bytes=383 protocol=https
2020-06-28T17:01:54.442464+00:00 heroku[router]: at=info method=POST path="/" host=peaceful-sierra-47869.herokuapp.com request_id=dea03d53-8229-49fc-88e0-0dc083afa904 fwd="75.71.7.56" dyno=web.1 connect=1ms service=35ms status=404 bytes=384 protocol=https
2020-06-28T17:02:07.616543+00:00 heroku[router]: at=info method=POST path="/signup" host=peaceful-sierra-47869.herokuapp.com request_id=42fa1047-67da-4d40-a559-165a45ec6668 fwd="75.71.7.56" dyno=web.1 connect=1ms service=14ms status=422 bytes=425 protocol=https
2020-06-28T17:02:19.649813+00:00 heroku[router]: at=info method=POST path="/signup" host=peaceful-sierra-47869.herokuapp.com request_id=8184a15b-928c-4cb3-8bb2-0793f8942bd3 fwd="75.71.7.56" dyno=web.1 connect=1ms service=5ms status=422 bytes=429 protocol=https
2020-06-28T17:02:51.161097+00:00 heroku[router]: at=info method=POST path="/signup" host=peaceful-sierra-47869.herokuapp.com request_id=2b65550d-1a68-499c-b65e-52a93727ba1c fwd="75.71.7.56" dyno=web.1 connect=1ms service=7ms status=422 bytes=321 protocol=https
2020-06-28T17:03:02.233071+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/signup" host=peaceful-sierra-47869.herokuapp.com request_id=676d4fac-d641-4f6f-ac2c-0623ceb95c31 fwd="75.71.7.56" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=https
2020-06-28T17:03:27.842943+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/signup" host=peaceful-sierra-47869.herokuapp.com request_id=e23ee5d6-6133-484b-83d1-d9aa8a8d805e fwd="75.71.7.56" dyno=web.1 connect=1ms service=30003ms status=503 bytes=0 protocol=https
2020-06-28T17:38:31.314094+00:00 heroku[web.1]: Idling
2020-06-28T17:38:31.316222+00:00 heroku[web.1]: State changed from up to down
2020-06-28T17:38:32.632834+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-06-28T17:38:32.800439+00:00 heroku[web.1]: Process exited with status 143
2020-06-28T18:41:53.590065+00:00 heroku[web.1]: Unidling
2020-06-28T18:41:53.633857+00:00 heroku[web.1]: State changed from down to starting
2020-06-28T18:41:56.534301+00:00 heroku[web.1]: Starting process with command `npm start`
2020-06-28T18:41:59.583503+00:00 app[web.1]:
2020-06-28T18:41:59.583531+00:00 app[web.1]: > myapp#1.0.0 start /app
2020-06-28T18:41:59.583531+00:00 app[web.1]: > node server.js
2020-06-28T18:41:59.583531+00:00 app[web.1]:
2020-06-28T18:42:00.831129+00:00 heroku[web.1]: State changed from starting to up
2020-06-28T18:42:15.614809+00:00 heroku[router]: at=info method=GET path="/" host=peaceful-sierra-47869.herokuapp.com request_id=106c03a3-bb7b-4aa0-a5dc-6ff21fbf9dfc fwd="75.71.7.56" dyno=web.1 connect=1ms service=6ms status=404 bytes=383 protocol=https
2020-06-28T18:42:18.614798+00:00 heroku[router]: at=info method=GET path="/" host=peaceful-sierra-47869.herokuapp.com request_id=84b3c61c-a58c-4040-b3fd-af97ec6a28ea fwd="75.71.7.56" dyno=web.1 connect=1ms service=4ms status=404 bytes=383 protocol=https
2020-06-28T18:42:30.472774+00:00 app[web.1]: connect succesfully!
2020-06-28T18:42:31.688047+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/signup" host=peaceful-sierra-47869.herokuapp.com request_id=35de2b28-ac52-4247-a52e-87206f35eb37 fwd="75.71.7.56" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0 protocol=https
2020-06-28T18:45:15.640333+00:00 heroku[router]: at=info method=GET path="/" host=peaceful-sierra-47869.herokuapp.com request_id=2ce30c29-d330-4c7a-a24d-82c0016b22fa fwd="75.71.7.56" dyno=web.1 connect=0ms service=4ms status=404 bytes=383 protocol=https
2020-06-28T18:45:58.206548+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/signup" host=peaceful-sierra-47869.herokuapp.com request_id=a57c93f5-cf60-4c28-b99f-9e924cbf6270 fwd="75.71.7.56" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0 protocol=https
2020-06-28T18:51:44.193312+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/signup" host=peaceful-sierra-47869.herokuapp.com request_id=fec8c8a1-d7c5-4393-8852-e36771cf1dfc fwd="75.71.7.56" dyno=web.1 connect=5ms service=30006ms status=503 bytes=0 protocol=https
2020-06-28T19:20:18.334810+00:00 heroku[web.1]: Idling
2020-06-28T19:20:18.337241+00:00 heroku[web.1]: State changed from up to down
2020-06-28T19:20:19.565141+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-06-28T19:20:19.664454+00:00 heroku[web.1]: Process exited with status 143
2020-06-28T21:05:43.391044+00:00 heroku[web.1]: Unidling
2020-06-28T21:05:43.407486+00:00 heroku[web.1]: State changed from down to starting
2020-06-28T21:05:46.540194+00:00 heroku[web.1]: Starting process with command `npm start`
2020-06-28T21:05:49.717362+00:00 app[web.1]:
2020-06-28T21:05:49.717420+00:00 app[web.1]: > myapp#1.0.0 start /app
2020-06-28T21:05:49.717426+00:00 app[web.1]: > node server.js
2020-06-28T21:05:51.082642+00:00 heroku[web.1]: State changed from starting to up
2020-06-28T21:05:52.504484+00:00 heroku[router]: at=info method=GET path="/users/1" host=peaceful-sierra-47869.herokuapp.com request_id=0f6e0493-a67d-4597-979f-f3c3a3091465 fwd="75.71.7.56" dyno=web.1 connect=1ms service=48ms status=200 bytes=246 protocol=https
2020-06-28T21:06:20.679758+00:00 app[web.1]: connect succesfully!
2020-06-28T21:07:34.667678+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/signup" host=peaceful-sierra-47869.herokuapp.com request_id=fb9ceb56-1991-483a-be45-95d339ad3cec fwd="75.71.7.56" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0 protocol=https
2020-06-28T21:08:41.256696+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/signup" host=peaceful-sierra-47869.herokuapp.com request_id=9fc27994-88bb-43c8-a9ef-b5e2aa20c6bf fwd="75.71.7.56" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=https
2020-06-28T21:16:20.848755+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/signup" host=peaceful-sierra-47869.herokuapp.com request_id=b0ac5b4c-9349-488a-8446-31dc01ed00fb fwd="75.71.7.56" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=http
2020-06-28T21:16:31.106986+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/signup" host=peaceful-sierra-47869.herokuapp.com request_id=b0ac31ae-4cb6-42b5-a99f-cc48564783a1 fwd="75.71.7.56" dyno=web.1 connect=0ms service=30002ms status=503 bytes=0 protocol=https
2020-06-28T21:22:32.020268+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/signup" host=peaceful-sierra-47869.herokuapp.com request_id=206ab63d-718a-43ea-899a-0200f4444106 fwd="75.71.7.56" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=https
## server.js
const express = require('express');
const mongoose = require('mongoose');
const app = express();
const PORT = 5000;
const routes = require('./routes');
const bodyParser = require('body-parser');
const jwt = require('jsonwebtoken');
app.use(bodyParser.json());
app.use(async (req, res, next) => {
if (req.headers && req.headers.authorization && req.headers.authorization.split(' ')[0]==='JWT') {
token = req.headers.authorization.split(' ')[1];
jwt.verify(token, 'secret', (err, decoded) => {
err? res.json(err.message) : req.user = decoded;
next();
} );
} else {
req.user = undefined;
next();
}
});
app.use('/', routes);
mongoose.connect('mongodb://localhost:27017/my_important_dates', {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
}, ()=>{
console.log('connect succesfully!');
});
app.listen(process.env.PORT || PORT);
## user routes
const express = require('express');
const eventRoutes = require('./event_routes');
// eslint-disable-next-line new-cap
const router = express.Router();
const validateUser = require('../validator');
const {getUser, updateUser, loginRequired, rightUser} = require('../controllers/usersController');
router.use(loginRequired);
router.route('/:id')
.get(getUser)
.put(rightUser, validateUser, updateUser);// You have to be the right user to change the user
router.use('/:id/events', eventRoutes);
module.exports = router;
## userController.js
const User = require('../models/user');
const bcrypt = require('bcrypt');
const jwt = require('jsonwebtoken');
const signUp = (req, res) => {
User.init()
.then( async ()=>{
const user = new User(req.body);
user.hashPassword = bcrypt.hashSync(req.body.password, 10);
const result = await user.save();
res.json(result);
})
.catch((err) => {
res.json(err);
});
};
module.exports = {getUser, signUp, updateUser, login, loginRequired, rightUser};
Since I got the error saying that request timeout, so I am guessing if it has to do with MongoDB database hanging?
Also, one thing that is strange, when I use wrong data to sign up, I did get error messages back, but when I use good data to request, the response is hanging there
But BTW whoever wants to restore the problem, here is the link: https://peaceful-sierra-47869.herokuapp.com/signup and you can make a post request to it with this:
"name": "aaa123",
"email": "l123#123.com",
"password": "pas8889"
}
Update: so I "fix" the problem by simply changing the MongoDB connect URL from localhost to MongoDB atlas URL. I don't know why the previous MongoDB URL doesn't work. So I didn't close the question. Please leave your answer if you know, but one thing to mention is that, if you use the API link, it will work now, but just bc I use MongoDB Atlas.
Thank you!
A connection URI in this format mongodb://localhost** refers to a database running locally on the server. - Source.
Unless you've installed MongoDB on your Heroku server(which I believe you did not), you won’t be able to connect to a MongoDB instance running locally on the server. This explains why the request was timing out when a DB operation is expected to happen and why changing the connection URI to reference a MongoDB Atlas instance fixed the problem.
I managed to get sockets to work on my LocalHost, however when uploading to Heroku I get the following errors.
Heroku logs:
2020-02-26T19:18:12.223451+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=N22xsN8" host=evening-beach-84352.herokuapp.com request_id=9e085385-d06d-42f8-a02b-741ebdb50139 fwd="99.239.140.92" dyno=web.1 connect=1ms service=7ms status=200 bytes=1156 protocol=https
2020-02-26T19:18:16.268249+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=N22xtMN" host=evening-beach-84352.herokuapp.com request_id=560a1283-e9ad-4f98-b65d-c98e3af0d989 fwd="99.239.140.92" dyno=web.1 connect=1ms service=7ms status=200 bytes=1156 protocol=https
2020-02-26T19:18:16.340518+00:00 heroku[router]: at=info method=POST path="/socket.io/?EIO=3&transport=polling&t=N22xtNI" host=evening-beach-84352.herokuapp.com request_id=0747c99f-bfa7-4a48-9dc9-396237ea4afd fwd="99.239.140.92" dyno=web.1 connect=1ms service=17ms status=404 bytes=417 protocol=https
2020-02-26T19:18:16.345722+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=N22xtNd" host=evening-beach-84352.herokuapp.com request_id=c28aa30e-c33f-4d2b-809d-7f723c9ad2f8 fwd="99.239.140.92" dyno=web.1 connect=1ms service=11ms status=200 bytes=1156 protocol=https
2020-02-26T19:18:16.394512+00:00 heroku[router]: at=info method=POST path="/socket.io/?EIO=3&transport=polling&t=N22xtOS" host=evening-beach-84352.herokuapp.com request_id=93635a58-6c21-4d1a-81b4-ba67c712bc4a fwd="99.239.140.92" dyno=web.1 connect=1ms service=3ms status=404 bytes=417 protocol=https
2020-02-26T19:18:18.146871+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=N22xtpq" host=evening-beach-84352.herokuapp.com request_id=8dc8077a-5719-4f97-bd60-dc2f9585efea fwd="99.239.140.92" dyno=web.1 connect=1ms service=5ms status=200 bytes=1156 protocol=https
2020-02-26T19:18:18.104971+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=N22xtp6" host=evening-beach-84352.herokuapp.com request_id=1a135498-5911-4757-90a6-52f22188b3ae fwd="99.239.140.92" dyno=web.1 connect=1ms service=8ms status=200 bytes=1156 protocol=https
2020-02-26T19:18:18.174618+00:00 heroku[router]: at=info method=POST path="/socket.io/?EIO=3&transport=polling&t=N22xtqB" host=evening-beach-84352.herokuapp.com request_id=dce824bb-5243-45be-bd9b-5be3026412ac fwd="99.239.140.92" dyno=web.1 connect=1ms service=3ms status=404 bytes=417 protocol=https
2020-02-26T19:18:18.235090+00:00 heroku[router]: at=info method=POST path="/socket.io/?EIO=3&transport=polling&t=N22xtr2" host=evening-beach-84352.herokuapp.com request_id=44dbc61d-5e40-4283-b602-77107c20bdcd fwd="99.239.140.92" dyno=web.1 connect=1ms service=7ms status=404 bytes=417 protocol=https
Browser console logs:
polling-xhr.js:271 POST https://evening-beach-84352.herokuapp.com/socket.io/?EIO=3&transport=polling&t=N22yWHd 404 (Not Found)
I have this set up on my client side code:
import socketIOClient from "socket.io-client";
const socket = socketIOClient("https://evening-beach-84352.herokuapp.com/")
And this one my server side code:
const server = require('http').Server(app);
const socketIO = require('socket.io')
const io = socketIO(server, { origin: "*:*" });
const PORT = process.env.PORT || 8080;
Have you enabled session affinity in your app? From the support article:
Apps using Socket.io should enable session affinity. If you plan to
use Node’s Cluster module or to scale your app to multiple dynos, you
should also follow Socket.io’s multiple-nodes instructions.
heroku features:enable http-session-affinity
I just started using Heroku recently and just added socket.io to my application and am seeing similar errors. Yesterday they went away, today they are back. I have two tabs in my browser 1 works the other doesn't...
The difference: http vs https
When you click the link in Heroku to take you to your app it navigates to https://myapp.herokuapp.com but if I manually navigate to http://myapp.herokuapp.com suddenly all the errors go away.
Now I'd like to know the reason why one works and the other doesn't...
//This is my server.js node file
var express=require('express')
var path=require('path')
var app=express()
var alfa=express.Router()
var port= (process.env.PORT || 5000)
app.use(express.static(__dirname+'/'))
alfa.get('/',function(req,res){
res.sendFile(path.join(__dirname+'index.html'))
});
alfa.get('/movies',function(req,res){
res.sendFile(path.join(__dirname+'movies.html'))
})
alfa.get('/shows',function(req,res){
res.sendFile(path.join(__dirname+'tvshows.html'))
})
app.use('/',alfa)
app.listen(port);
console.log('Go to the port : ' + port);
The index.html has a href to movies.html file.
Findout More...<span class="fa fa-chevron-circle-right">
After deploying to heroku cloud when running the application, the first page loads(without proper css;linked to an external css file, which is expected to be of a similar issue).
On click of the movies href link the error appears in the browser saying internal server error or page not found.
Later I checked the Heroku logs for the application and it says as below:
/app is appended before the href path movies.html
2016-01-30T00:27:06.417098+00:00 heroku[router]: at=info method=GET path="/scrol
l.js" host=alfapalakoti.herokuapp.com request_id=6b078679-71a4-436e-9b22-ab87de6
7c534 fwd="50.156.90.248" dyno=web.1 connect=1ms service=47ms status=200 bytes=6
70
2016-01-30T00:27:06.527645+00:00 heroku[router]: at=info method=GET path="/tv.pn
g" host=alfapalakoti.herokuapp.com request_id=05d76121-4af2-4d65-8425-ff4df7684a
6f fwd="50.156.90.248" dyno=web.1 connect=1ms service=14ms status=200 bytes=1499
9
2016-01-30T00:27:06.532690+00:00 heroku[router]: at=info method=GET path="/timer
.png" host=alfapalakoti.herokuapp.com request_id=5438c650-65e2-4f21-8c10-346f71c
60182 fwd="50.156.90.248" dyno=web.1 connect=1ms service=11ms status=200 bytes=2
5665
2016-01-30T00:27:06.540491+00:00 heroku[router]: at=info method=GET path="/shows
.jpg" host=alfapalakoti.herokuapp.com request_id=7afbf80b-071d-4ab1-9c18-cb36c71
f444b fwd="50.156.90.248" dyno=web.1 connect=1ms service=33ms status=200 bytes=3
69678
2016-01-30T00:27:06.625994+00:00 heroku[router]: at=info method=GET path="/carou
selbg.jpg" host=alfapalakoti.herokuapp.com request_id=2c371ea0-d47b-46e2-b9a1-51
28fbfaba4a fwd="50.156.90.248" dyno=web.1 connect=1ms service=112ms status=200 b
ytes=2069053
2016-01-30T00:27:06.781953+00:00 heroku[router]: at=info method=GET path="/mainb
g.jpg" host=alfapalakoti.herokuapp.com request_id=e43a6ac3-0b68-40f6-95ba-edc988
a57a91 fwd="50.156.90.248" dyno=web.1 connect=1ms service=6ms status=200 bytes=1
1178
2016-01-30T00:27:06.623717+00:00 heroku[router]: at=info method=GET path="/movie
s.jpg" host=alfapalakoti.herokuapp.com request_id=61d32aa0-0158-4962-8f8c-5f1a30
2e8654 fwd="50.156.90.248" dyno=web.1 connect=1ms service=259ms status=200 bytes
=4974518
2016-01-30T00:27:16.482080+00:00 heroku[router]: at=info method=GET path="/movie
s" host=alfapalakoti.herokuapp.com request_id=efc2a66c-6ec0-4e76-9afb-39384b8513
52 fwd="50.156.90.248" dyno=web.1 connect=1ms service=14ms status=404 bytes=208
2016-01-30T00:27:16.492630+00:00 app[web.1]: Error: ENOENT: no such file or dire
ctory, stat '**/appmovies.html'**
2016-01-30T00:27:16.492634+00:00 app[web.1]: at Error (native)
2016-01-30T01:00:47.163686+00:00 heroku[web.1]: State changed from up to down
2016-01-30T01:00:47.162812+00:00 heroku[web.1]: Idling
2016-01-30T01:00:54.049172+00:00 heroku[web.1]: Stopping all processes with SIGT
ERM
2016-01-30T01:00:57.704556+00:00 heroku[web.1]: Process exited with status 143
//can someone please help me with this?
//why is that being added? How to get rid of it?