Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

403
Views
to be under different domain, why axios.post dont work

https://github.com/skyturkish/e_commerce_advance this is the repo

index.js

const express = require('express')
const bodyParser = require('body-parser')


const UserService = require('./services/user-service')
const app = express()

app.set('view engine', 'pug')
app.use(bodyParser.json())

app.get('/', (req, res) => {
    res.render('index')
})

app.get('/users/all', async (req, res) => {
    const users = await UserService.findAll()
    res.render('user', { users })
})

app.get('/users/:id', async (req, res) => {
    const user = await UserService.find(req.params.id)
    res.send(user)
})

app.post('/users', async (req, res) => {
    const user = await UserService.add(req.body)
    res.send(user)
})

app.delete('/users/:id', async (req, res) => {
    const user = await UserService.del(req.params.id)
    res.send(user)
})

app.listen(3000, () => {
    console.log('Server listening')
})

When I try to add a new user under "http://localhost:3000/" or "http://localhost:3000/users/all", this works. But under http://localhost:3000/users/1 throw an error. I cant understand well, why this happens, how does being under a domain authorize and receive it.

enter image description here

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The GET handlers for / and /users/all use res.render(), but the GET handler for /users/:id uses res.send() (so it doesn't render your template, which in turn loads the axios library).

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!