简体   繁体   中英

Postman Returning 404 for post route

I am new to postman and am trying to do some test uploads to cloudinary. However when i try do some test uploads i am getting status 404 not found in my localhost:5000/api and localhost:5000/api/upload.

Here is my upload.js where i am using router.post:

const router = require("express").Router();
const cloudinary = require("cloudinary");
const fs = require("fs");

//UPLOAD TO CLODUINARY
cloudinary.config({
  cloud_name: process.env.CLOUD_NAME,
  api_key: process.env.CLOUD_API_KEY,
  api_secret: process.env.CLOUD_API_SECRET,
});

//upload image
router.post("./upload", (req, res) => {
  try {
    console.log(req.files);
    res.json("test upload");
  } catch (error) {
    res.status(500).json({ msg: error.message });
  }
});

module.exports = router;

used in server.js:

const productRoutes = require("./routes/productRoutes");
const uploadRoutes = require("./routes/upload");

app.use("/api", uploadRoutes);
app.use("/api/products", productRoutes);

const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));

I dont end up seeing my "test upload message" and postman doesnt seem to be able to connect to it.:

邮差

Any help would be much appreciated

Your route should be /upload not ./upload . I'm not sure whether that is a typo but either way please consider reading the docs on express router .

This seems to be a routing issue from the response returned from postman.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM