PostgreSQL, Heroku, Express.Router(), CRUD send requests give as 404 status

I keep getting this error when I send a request.

2020-02-02T22:20:36.472438+00:00 heroku[router]: at=info method=POST path="/user/register" host=test-test.herokuapp.com request_id=5b08e9b1-406e-4af0-a3ca-a423b8a4ff03 fwd="23.101.44.185" dyno=web.1 connect=0ms service=35ms status=404 bytes=589 protocol=https

This is just for backend endpoints, there is not react app on this. I think this is a problem with the mapping of routes, meaning heroku I guess doesn’t know where to look?

I’m not sure how to fix this.

knexfile.js

require("dotenv").config();

module.exports = {
  development: {
    client: "pg",
    connection: {
      host: process.env.PGHOST,
      port: process.env.PGPORT,
      database: process.env.PGDATABASE,
      user: process.env.PGUSER,
      password: process.env.PGPASSWORD,
      ssl: process.env.PGSSL
    },
    migrations: {
      directory: "./data/migrations"
    },
    seeds: {
      directory: "./data/seeds/dev"
    },
    useNullAsDefault: true
  },

index.js

require('dotenv').config()

const server = require('./api/server');

const port = process.env.PORT || 8015;

server.listen(port, () => {
    console.log(`Server listening on port ${port}`)
})

server.js

// package imports

const express = require('express');

const helmet = require('helmet');

const cors = require('cors');

// creating express server

const server = express();

// importing routers here

const userRouter = require('./users/users-router');

// server routing

server.use('/api/', userRouter);

// importing middleware here

server.use(helmet(), cors(), express.json());

// middleware server.use here

server.get('/', (req, res) => {

res.send(`Server is LIVE and working.`)

});

module.exports = server;

If somebody can lead me in the right direction on how to fix this, that would be really awesome!

I’m using POSTMAN to send requests to /user/register, with a body.

The return is this

Cannot POST /user/register

Status 404 famously means there is no such endpoint and if you look at your server.js there seems to be no handler for /user/register route

Naming suggests this might be a problem, did you mean server.use('/user/', userRouter);?