Spaces:
Running
Running
Commit
·
7933ed3
1
Parent(s):
f7c1a11
refactor: index and app
Browse files- package-lock.json +89 -0
- package.json +1 -0
- src/configs/app.ts +0 -17
- src/index.route.ts +21 -29
- src/index.ts +26 -4
package-lock.json
CHANGED
@@ -21,6 +21,7 @@
|
|
21 |
"path": "^0.12.7"
|
22 |
},
|
23 |
"devDependencies": {
|
|
|
24 |
"nodemon": "^3.0.2",
|
25 |
"ts-node": "^10.9.2",
|
26 |
"typescript": "^5.3.3"
|
@@ -159,6 +160,61 @@
|
|
159 |
"integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==",
|
160 |
"dev": true
|
161 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
"node_modules/@types/node": {
|
163 |
"version": "20.10.4",
|
164 |
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.4.tgz",
|
@@ -167,6 +223,39 @@
|
|
167 |
"undici-types": "~5.26.4"
|
168 |
}
|
169 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
"node_modules/@types/webidl-conversions": {
|
171 |
"version": "7.0.3",
|
172 |
"resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz",
|
|
|
21 |
"path": "^0.12.7"
|
22 |
},
|
23 |
"devDependencies": {
|
24 |
+
"@types/express": "^4.17.21",
|
25 |
"nodemon": "^3.0.2",
|
26 |
"ts-node": "^10.9.2",
|
27 |
"typescript": "^5.3.3"
|
|
|
160 |
"integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==",
|
161 |
"dev": true
|
162 |
},
|
163 |
+
"node_modules/@types/body-parser": {
|
164 |
+
"version": "1.19.5",
|
165 |
+
"resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.5.tgz",
|
166 |
+
"integrity": "sha512-fB3Zu92ucau0iQ0JMCFQE7b/dv8Ot07NI3KaZIkIUNXq82k4eBAqUaneXfleGY9JWskeS9y+u0nXMyspcuQrCg==",
|
167 |
+
"dev": true,
|
168 |
+
"dependencies": {
|
169 |
+
"@types/connect": "*",
|
170 |
+
"@types/node": "*"
|
171 |
+
}
|
172 |
+
},
|
173 |
+
"node_modules/@types/connect": {
|
174 |
+
"version": "3.4.38",
|
175 |
+
"resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz",
|
176 |
+
"integrity": "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==",
|
177 |
+
"dev": true,
|
178 |
+
"dependencies": {
|
179 |
+
"@types/node": "*"
|
180 |
+
}
|
181 |
+
},
|
182 |
+
"node_modules/@types/express": {
|
183 |
+
"version": "4.17.21",
|
184 |
+
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.21.tgz",
|
185 |
+
"integrity": "sha512-ejlPM315qwLpaQlQDTjPdsUFSc6ZsP4AN6AlWnogPjQ7CVi7PYF3YVz+CY3jE2pwYf7E/7HlDAN0rV2GxTG0HQ==",
|
186 |
+
"dev": true,
|
187 |
+
"dependencies": {
|
188 |
+
"@types/body-parser": "*",
|
189 |
+
"@types/express-serve-static-core": "^4.17.33",
|
190 |
+
"@types/qs": "*",
|
191 |
+
"@types/serve-static": "*"
|
192 |
+
}
|
193 |
+
},
|
194 |
+
"node_modules/@types/express-serve-static-core": {
|
195 |
+
"version": "4.17.41",
|
196 |
+
"resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.41.tgz",
|
197 |
+
"integrity": "sha512-OaJ7XLaelTgrvlZD8/aa0vvvxZdUmlCn6MtWeB7TkiKW70BQLc9XEPpDLPdbo52ZhXUCrznlWdCHWxJWtdyajA==",
|
198 |
+
"dev": true,
|
199 |
+
"dependencies": {
|
200 |
+
"@types/node": "*",
|
201 |
+
"@types/qs": "*",
|
202 |
+
"@types/range-parser": "*",
|
203 |
+
"@types/send": "*"
|
204 |
+
}
|
205 |
+
},
|
206 |
+
"node_modules/@types/http-errors": {
|
207 |
+
"version": "2.0.4",
|
208 |
+
"resolved": "https://registry.npmjs.org/@types/http-errors/-/http-errors-2.0.4.tgz",
|
209 |
+
"integrity": "sha512-D0CFMMtydbJAegzOyHjtiKPLlvnm3iTZyZRSZoLq2mRhDdmLfIWOCYPfQJ4cu2erKghU++QvjcUjp/5h7hESpA==",
|
210 |
+
"dev": true
|
211 |
+
},
|
212 |
+
"node_modules/@types/mime": {
|
213 |
+
"version": "1.3.5",
|
214 |
+
"resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.5.tgz",
|
215 |
+
"integrity": "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==",
|
216 |
+
"dev": true
|
217 |
+
},
|
218 |
"node_modules/@types/node": {
|
219 |
"version": "20.10.4",
|
220 |
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.4.tgz",
|
|
|
223 |
"undici-types": "~5.26.4"
|
224 |
}
|
225 |
},
|
226 |
+
"node_modules/@types/qs": {
|
227 |
+
"version": "6.9.11",
|
228 |
+
"resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.11.tgz",
|
229 |
+
"integrity": "sha512-oGk0gmhnEJK4Yyk+oI7EfXsLayXatCWPHary1MtcmbAifkobT9cM9yutG/hZKIseOU0MqbIwQ/u2nn/Gb+ltuQ==",
|
230 |
+
"dev": true
|
231 |
+
},
|
232 |
+
"node_modules/@types/range-parser": {
|
233 |
+
"version": "1.2.7",
|
234 |
+
"resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.7.tgz",
|
235 |
+
"integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==",
|
236 |
+
"dev": true
|
237 |
+
},
|
238 |
+
"node_modules/@types/send": {
|
239 |
+
"version": "0.17.4",
|
240 |
+
"resolved": "https://registry.npmjs.org/@types/send/-/send-0.17.4.tgz",
|
241 |
+
"integrity": "sha512-x2EM6TJOybec7c52BX0ZspPodMsQUd5L6PRwOunVyVUhXiBSKf3AezDL8Dgvgt5o0UfKNfuA0eMLr2wLT4AiBA==",
|
242 |
+
"dev": true,
|
243 |
+
"dependencies": {
|
244 |
+
"@types/mime": "^1",
|
245 |
+
"@types/node": "*"
|
246 |
+
}
|
247 |
+
},
|
248 |
+
"node_modules/@types/serve-static": {
|
249 |
+
"version": "1.15.5",
|
250 |
+
"resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.15.5.tgz",
|
251 |
+
"integrity": "sha512-PDRk21MnK70hja/YF8AHfC7yIsiQHn1rcXx7ijCFBX/k+XQJhQT/gw3xekXKJvx+5SXaMMS8oqQy09Mzvz2TuQ==",
|
252 |
+
"dev": true,
|
253 |
+
"dependencies": {
|
254 |
+
"@types/http-errors": "*",
|
255 |
+
"@types/mime": "*",
|
256 |
+
"@types/node": "*"
|
257 |
+
}
|
258 |
+
},
|
259 |
"node_modules/@types/webidl-conversions": {
|
260 |
"version": "7.0.3",
|
261 |
"resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz",
|
package.json
CHANGED
@@ -12,6 +12,7 @@
|
|
12 |
"author": "",
|
13 |
"license": "ISC",
|
14 |
"devDependencies": {
|
|
|
15 |
"nodemon": "^3.0.2",
|
16 |
"ts-node": "^10.9.2",
|
17 |
"typescript": "^5.3.3"
|
|
|
12 |
"author": "",
|
13 |
"license": "ISC",
|
14 |
"devDependencies": {
|
15 |
+
"@types/express": "^4.17.21",
|
16 |
"nodemon": "^3.0.2",
|
17 |
"ts-node": "^10.9.2",
|
18 |
"typescript": "^5.3.3"
|
src/configs/app.ts
DELETED
@@ -1,17 +0,0 @@
|
|
1 |
-
import dotenv from "dotenv";
|
2 |
-
dotenv.config();
|
3 |
-
import express from "express";
|
4 |
-
import bodyParser from "body-parser";
|
5 |
-
import cors from "cors";
|
6 |
-
import path from 'path';
|
7 |
-
import { routes } from "../index.route";
|
8 |
-
import { connection as databaseConnection } from "./database";
|
9 |
-
|
10 |
-
databaseConnection();
|
11 |
-
export const app = express();
|
12 |
-
app.use(cors());
|
13 |
-
app.use(express.json());
|
14 |
-
app.use(routes);
|
15 |
-
app.use(bodyParser.json());
|
16 |
-
|
17 |
-
app.use(bodyParser.urlencoded({ extended: false }));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/index.route.ts
CHANGED
@@ -1,38 +1,30 @@
|
|
1 |
-
import express from
|
2 |
-
const app = express.Router();
|
3 |
-
|
4 |
-
import { userRoutes } from './modules/user/index.route';
|
5 |
-
import { adminRoutes } from './modules/console/index.route';
|
6 |
-
|
7 |
-
app.use("/api/v1/user", userRoutes);
|
8 |
-
app.use("/api/v1/admin", adminRoutes);
|
9 |
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
})
|
14 |
-
|
15 |
-
app.get("*", (req: any, res: any) => {
|
16 |
-
res.status(404).json({ success: false, message: "Invalid URL!", code: 404 })
|
17 |
-
})
|
18 |
-
|
19 |
-
app.post("*", (req: any, res: any) => {
|
20 |
-
res.status(404).json({ success: false, message: "Invalid URL!", code: 404 })
|
21 |
-
})
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
})
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
})
|
30 |
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
})
|
35 |
|
|
|
|
|
|
|
36 |
|
|
|
37 |
|
38 |
-
export { app as routes };
|
|
|
1 |
+
import express from "express";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
const app = express.Router();
|
4 |
|
5 |
+
import { userRoutes } from "./modules/user/index.route";
|
6 |
+
import { adminRoutes } from "./modules/console/index.route";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
// set prefix for all routes
|
9 |
+
const v1Router = express.Router();
|
|
|
10 |
|
11 |
+
v1Router.use("/user", userRoutes);
|
12 |
+
v1Router.use("/admin", adminRoutes);
|
|
|
13 |
|
14 |
+
v1Router.get("/", (_req: any, res: any) => {
|
15 |
+
res
|
16 |
+
.status(200)
|
17 |
+
.json({ success: true, message: "Welcome Message", code: 200 });
|
18 |
+
});
|
19 |
|
20 |
+
v1Router.get("/health", (_req: any, res: any) => {
|
21 |
+
res.status(200).json({ success: true, message: "Server is up!", code: 200 });
|
22 |
+
});
|
23 |
|
24 |
+
v1Router.all("*", (_req: any, res: any) => {
|
25 |
+
res.status(404).json({ success: false, message: "Invalid URL!", code: 404 });
|
26 |
+
});
|
27 |
|
28 |
+
app.use("/api/v1", v1Router);
|
29 |
|
30 |
+
export { app as routes };
|
src/index.ts
CHANGED
@@ -1,5 +1,27 @@
|
|
1 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import dotenv from "dotenv";
|
2 |
+
dotenv.config();
|
3 |
+
import express from "express";
|
4 |
+
import bodyParser from "body-parser";
|
5 |
+
import cors from "cors";
|
6 |
+
import { routes } from "./index.route";
|
7 |
+
import { connection as databaseConnection } from "./configs/database";
|
8 |
|
9 |
+
const main = async () => {
|
10 |
+
// set up database connection
|
11 |
+
databaseConnection();
|
12 |
+
|
13 |
+
// set up express server
|
14 |
+
const app = express();
|
15 |
+
app.use(cors());
|
16 |
+
app.use(express.json());
|
17 |
+
app.use(routes);
|
18 |
+
app.use(bodyParser.json());
|
19 |
+
app.use(bodyParser.urlencoded({ extended: false }));
|
20 |
+
|
21 |
+
// start server
|
22 |
+
app.listen(process.env.PORT || 4000, () => {
|
23 |
+
console.log(`Server is up and running on port ${process.env.PORT}!`);
|
24 |
+
});
|
25 |
+
};
|
26 |
+
|
27 |
+
main();
|