Tim Visser Tim Visser - 3 months ago 25
Node.js Question

KrakenJS controller routing

I have an admin controller

controllers/admin.js
that looks like this:

"use strict";

var AdminModel = require('../models/admin');


module.exports = function (router) {

var model = new AdminModel();

router.get('/admin', function (req, res) {

res.send("Admin");

});
};


If I start the application, getting the URL of http://localhost:8000/admin gives me
Cannot GET /admin
. However, getting /admin/admin gives me
Admin
.

My question is how do I get rid of the controller file name in the path of the URL?

Answer

first option is remove admin from router.get in admin.js controller

router.get('/admin', function (req, res) {

second check configuration in config director

config.json "router": { "module": { "arguments": [{ "directory": "path:./controllers" }] } }

for more study on controllers directory configuration : https://github.com/krakenjs/express-enrouten

Comments