-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (40 loc) · 1.7 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Import dependencies
require("dotenv").config();
const express = require("express");
const logger = require("morgan");
const cors = require('cors');
// MongoDB connections
const connect_to_database = require("./db_connection");
// Routers
const regions_router = require('./routes/regions_route');
const states_router = require('./routes/states_route');
const local_gov_areas_router = require('./routes/local_gov_areas_route');
const search_router = require('./routes/search_route');
const users_router = require('./routes/users_route');
const app = express();
const PORT = process.env.PORT || 5000;
// DB connection
connect_to_database();
// App level Middleware.
app.use(express.json())
app.use(logger('dev'));
app.use(cors());
// Route Middleware
app.use("/api/nigeria/regions", regions_router);
app.use("/api/nigeria/states", states_router);
app.use("/api/nigeria/local_government_areas", local_gov_areas_router);
app.use("/api/nigeria/search", search_router);
app.use("/api/users", users_router);
// Base route
app.get("/", (req, res)=> {
res.status(200).send("Locale is a developer tool for anyone who needs to know Nigeria, geographically at least. Locale’s API shows you all of Nigeria’s regions, states, and local government areas(LGAs). Locale is looking to be a very useful tool for the thousands of businesses building for Nigeria’s 200M+ population size.")
});
app.get("/api", (req, res)=> {
res.status(200).send("Welcome to Locale API, check out the link: \"https://muhdibee.stoplight.io/docs/locale/\" for documentation on how this API works.")
});
app.get("*", (req, res)=> {
res.status(404).send("Route not supported.")
});
app.listen(PORT, ()=>{
console.log("Listening on port: ", PORT);
})