I have problems with the REST API.
I have a file named Route. In which I make a request that is then passed to the server where it is called. In my third request, I want to select an ID to pass it as an API and write to call the page inside/:id, but I only get an error (This is a POST request)
Error: Cannot POST /inside
Route.js
const post_inside = (req, res) => {
var config = {
user:'postgres',
database:'my',
password: '1',
host:'localhost',
port:5432,
max:10,
idleTimeoutMillis: 30000
}
var pool = new pg.Pool(config)
pool.connect(function(err, client, done){
if(err){
return console.error('error')
}
client.query("SELECT *,to_char(data_roz::date , 'YYYY-MM-DD') as data_roz from sch.idv_p where phone=$1",[req.body.login], function(err, result){
done()
return_data.pupil2 =result
if (err) {
res.end()
return console.error("error")
}
client.query('select * from table1 ($1,$2)',[req.body.login,req.body.date], function(err, result){
return_data.discipline =result
if (err){
res.end()
return console.error("error")
}
//3 HERE
client.query("select id from table3 where phone=$1",[req.body.login], function(err, result){
return_data.id =result
if (err){
res.end()
return console.error("error")
}
res.render('inside',{pupil2:return_data.pupil2,discipline:return_data.discipline,id:return_data.id})
})})}}
module.exports = {
post_inside
}
server.js
app.post('/inside/:id',urlencodedParser,db.post_inside)
I want to call the same file, but for example as inside/2124
try to remove urlencodedParser from app.post from 2nd parameter and keep db.post_inside as 2nd parameter.
instead of that try to use
app.use(bodyParser.urlencoded({ extended: true })) // true or false
app.use(bodyParser.json())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.