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

412
Views
estar bajo un dominio diferente, ¿por qué axios.post no funciona?

https://github.com/skyturkish/e_commerce_advance este es el repositorio

índice.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') })

Cuando intento agregar un nuevo usuario en "http://localhost:3000/" o "http://localhost:3000/users/all", esto funciona. Pero en http://localhost:3000/users/1 arroja un error. No entiendo bien por qué sucede esto, cómo autorizar y recibir el estar bajo un dominio.

ingrese la descripción de la imagen aquí

ingrese la descripción de la imagen aquí

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

0

Los controladores GET para / y /users/all usan res.render() , pero el controlador GET para /users/:id usa res.send() (por lo que no representa su plantilla, que a su vez carga la biblioteca axios ).

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!