0

I'm refactoring my Angular4+sails app so that both the views and the backend are available on localhost:1337. I've specified the routes in config/routes.js

module.exports.routes = {

     '/': {
       view: 'homepage'
     },
     '/register':{
       view: 'homepage'
     },

     'POST /user': 'UserController.create',
     'POST /user/login': 'UserController.login',
     /*further code*/

};

and I have the UserController file with login method declared as follows:

import { Model } from 'Sails';

declare var sails: any;

module.exports = {

    login: function (req, res) {
        console.log("In controller");
        /*further code*/
    },
/*further code*/

};

all code is available here: https://github.com/adzina/web-app-1337

I access the homepage view at localhost:1337.Login button declared in assets/app/components/LoginComponent/ performs a POST request to localhost:1337/user/login and the response I get is: Response with status: 404 Not Found for URL: http://localhost:1337/user/login. Any ideas what could be causing this?

K.W.
  • 59
  • 1
  • 10
  • Do you maybe have a policy blocking the methods of your user controller? – arbuthnott Feb 01 '18 at 15:18
  • @arbuthnott in my config/policies.js I don't have any policy that affects the login method. All policies affecting the UserController are described as follows: UserController: { create: 'sessionAuth', getAll: 'sessionAuth', findByID: 'sessionAuth', }, – K.W. Feb 01 '18 at 16:17
  • Have you tried hitting http://localhost:1337/user/login directly from the broswer. – Glen Feb 08 '18 at 13:48
  • Have you tried accessing the API via `Postman` or any rest client? Are you able to do that? – khushalbokadey Feb 10 '18 at 10:00
  • @khushalbokadey turns out I had to add require('ts-node/register') to my app.js file. Since my server was written in typescript it was not being compiled to javascript. – K.W. Feb 12 '18 at 10:52

0 Answers0