Skip to content

Commit 56c7898

Browse files
committed
Admin test route
1 parent f3e2c3e commit 56c7898

File tree

6 files changed

+28
-4
lines changed

6 files changed

+28
-4
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/node_modules
2-
package-lock.json
2+
package-lock.json
3+
/config
4+
.env

config/dev.env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PORT=5000

controllers/adminControllers.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// name the controllers in this format '<method of request><Name of the route>'
2+
exports.getTest = (req, res, next) => {
3+
res.send("Admin Test");
4+
};

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "Web Project For MAIT-Interns",
55
"main": "server.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"dev": "env-cmd ./config/dev.env nodemon src/index.js"
89
},
910
"repository": {
1011
"type": "git",
@@ -21,5 +22,9 @@
2122
"express": "^4.16.4",
2223
"mongoose": "^5.5.1",
2324
"multer": "^1.4.1"
25+
},
26+
"devDependencies": {
27+
"env-cmd": "^8.0.2",
28+
"nodemon": "^1.18.11"
2429
}
2530
}

routes/adminRoutes.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const express = require("express");
2+
const router = express.Router();
3+
const adminControllers = require("../controllers/adminControllers");
4+
5+
// final route is /admin/test
6+
router.get("/test", adminControllers.getTest);
7+
8+
module.exports = router;

server.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const bodyParser = require("body-parser");
66
const app = express();
77

88
const userRoutes = require("./routes/userRoutes");
9+
const adminRoutes = require("./routes/adminRoutes");
910

1011
const PORT = process.env.PORT || 5000;
1112

@@ -19,10 +20,13 @@ app.use(express.static(path.join(__dirname, "client")));
1920
// User route
2021
app.use("/user", userRoutes);
2122

23+
// Admin route
24+
app.use("/admin", adminRoutes);
25+
2226
app.get("/", (req, res, next) => {
2327
res.sendFile(__dirname + "/client/index.html");
2428
});
2529

2630
app.listen(PORT, () => {
27-
console.log("Server has started");
28-
});
31+
console.log(`Server has started on port ${PORT}`);
32+
});

0 commit comments

Comments
 (0)