C
C
campus12019-02-09 15:34:01
Node.js
campus1, 2019-02-09 15:34:01

Why not available routes??

Hello.
Deployed app on heroku ( React + Node.js (Express ) ). I try to knock on the routes - but I get errors
404 Not Found - Cannot POST the name of the route

Route - https://protected-reef-88922.herokuapp.com/auth/facebook
const express = require('express');
const router = express.Router();
const { generateToken, sendToken } = require('../utils/token.utils');
const passport = require('passport');
require('../passport')();

/**
 *  Method: POST
 *  Route: /facebook
 *  Auth with facebook
 */
router.route('/facebook').post(
  passport.authenticate('facebook-token', { session: false }),
  function(req, res, next) {
    if (!req.user) {
      return res.send(401, 'User Not Authenticated');
    }
    req.auth = {
      id: req.user.id,
    };
    next();
  },
  generateToken,
  sendToken,
);

module.exports = router;


My server.js
const express = require("express");
const app = express();
const cors = require("cors");
const logger = require("morgan");
const cookieParser = require("cookie-parser");
const bodyParser = require("body-parser");
const path = require("path");

const auth = require("./routes/auth");
const report = require("./routes/report");
const reports = require("./routes/reports");

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

/**
 * Cors setup
 * @type {{credentials: boolean, methods: string, exposedHeaders: string[], origin: boolean}}
 */
const corsOption = {
  origin: true,
  methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
  credentials: true,
  exposedHeaders: ["Access-Token"],
};
app.use(cors(corsOption));

app.use(logger("dev"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());

app.use("/api/v1/auth", auth);
app.use("/api/v1/report", report);
app.use("/api/v1/reports", reports);

app.use(express.static("client/build"));

app.get("*", (req, res) => {
  res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});

app.listen(port, () => console.log(`Server is running on port ${port}`));

module.exports = app;

Here is the project itself - https://github.com/Slasherio/test

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question