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.
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).