Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot GET /register on heroku server error #60

Open
purveshshende2 opened this issue Apr 27, 2020 · 0 comments
Open

Cannot GET /register on heroku server error #60

purveshshende2 opened this issue Apr 27, 2020 · 0 comments

Comments

@purveshshende2
Copy link

I Cannot GET /register on heroku server error , it send 404 bad request

server.js

`const express = require('express');
const bodyParser = require('body-parser');
const bcrypt = require('bcrypt');
const cors = require('cors');
const knex = require('knex');
const register = require ('./controllers/register');
const signin = require('./controllers/signin');
const profile = require('./controllers/profile');
const image = require('./controllers/image');

const db = knex({
client: 'pg',
connection: {
connectionString: process.env.DATABASE_URL,
ssl: true,
}
});

const app = express();
app.use(cors())
app.use(bodyParser.json());

app.get('/',(req,res) => {res.send('it is Working!')})
app.post ('/signin', signin.handleSignin(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(process.env.PORT || 3000, () => {
console.log(app is running on port ${process.env.PORT});
})`

Register.js

`

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 saltRounds = 10;
const hash = bcrypt.hashSync(password,saltRounds);
const salt = bcrypt.genSaltSync(saltRounds);
db.transaction(trx => {
trx.insert({
hash : hash,
email : email
})
.into ('login')
.returning('email')
.then(loginEmail => {
return trx('users1')
.returning('*')
.insert ({
email : loginEmail[0],
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'))

}

module.exports = {
handleRegister : handleRegister
};
`
server_file.txt
registerfile.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant