I am getting the above error message in my Postman while setting up a new POST request using my heroku url as initial and current values in Globals. Postman returns 'Route does not exist' and when I check the Postman console I get "JSONError: Unexpected token 'R' at 1:1 Route does not exist ^" Postman worked fine up until now I am trying to use heroku with it. The POST request still works fine while the url is local://host/api/v1 ... however with heroku url is gives back that error message. I don't know what I am doing wrong and I have been stuck since last week, help will be appreciated. Thank you
THIS IS MY app.js CODE
require('dotenv').config();
require('express-async-errors');
//extra security packages
const helmet = require('helmet')
const cors = require('cors')
const xss = require('xss-clean')
const rateLimiter = require('express-rate-limit')
const express = require('express');
const app = express();
//connecting dB
const connectDB = require('./db/connect')
const authenticateUser = require('./middleware/authentication')
//import routes
const authRouter = require('./routes/auth')
const jobsRouter = require('./routes/jobs')
// error handler
const notFoundMiddleware = require('./middleware/not-found');
const errorHandlerMiddleware = require('./middleware/error-handler');
app.set('trust proxy', 1)
//built in mW
app.use(
rateLimiter({
windowMs: 15 * 60 * 1000, //15 minutes
max: 100, //limit each IP to 100 request per wMs
})
);
app.use(express.json());
app.use(helmet());
app.use(cors());
app.use(xss());
// routes - full path
app.use('/api/v1/auth', authRouter)
app.use('/api/v1/jobs', authenticateUser, jobsRouter) //authUser is added to this route to prevent unauthorized access to the Jobs route and prevent editing
app.use(notFoundMiddleware);
app.use(errorHandlerMiddleware);
const port = process.env.PORT || 5000;
const start = async () => {
try {
await connectDB(process.env.MONGO_URI)
app.listen(port, () =>
console.log(`Server is listening on port ${port}...`)
);
} catch (error) {
console.log(error);
}
};
start();
THIS is my auth code
const User = require('../models/User')
const {StatusCodes} = require('http-status-codes')
const { BadRequestError, UnauthenticatedError } = require('../errors')
const register = async (req,res) => {
const user = await User.create({...req.body})//'{...req.body}' enables mongoose to do the user validation
const token = user.createJWT()
res
.status(StatusCodes.CREATED)
.json({user:{name:user.name}, token})
}
const login = async (req,res) => {
const {email,password} = req.body
if(!email || !password){
throw new BadRequestError('Please provide email and password')
}
const user = await User.findOne({email})
if(!user){
throw new UnauthenticatedError('Invalid Credentials')
}
const isPasswordCorrect = await user.comparePassword(password)
if(!isPasswordCorrect){
throw new UnauthenticatedError('Invalid Credentials')
}
const token = user.createJWT()
res
.status(StatusCodes.OK)
.json({user:{name:user.name},token})
}
module.exports = {
register,
login,
}
THIS is my routes code
const express = require('express')
const router = express.Router()
const {login,register} = require('../controllers/auth')
router.post('/register', register)
router.post('/login', login)
module.exports = router