Reputation: 919
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?
Upvotes: 1
Views: 223
Reputation: 120
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" }]
}
}
edit :
third option create a folder admin in controllers folder copy index.js file from controllers folder result end url "/admin" (don't forget to change require location) and any other file in admin folder like "log.js" (path:"controllers/admin/log.js") create end url "/admin/log" by this method you an keep all admin code in different folder, this method helps managing large projects sometime to many folder also create mess ;)
router.get in admin/index.js or in log.js
router.get('/', function (req, res) {
using third method in my two projects for more study on controllers directory configuration : https://github.com/krakenjs/express-enrouten
Upvotes: 1