@ifecodes/backend-template 1.1.3 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -18
- package/bin/cli.js +207 -80
- package/bin/lib/microservice-config.js +57 -13
- package/bin/lib/prompts.js +10 -6
- package/bin/lib/readme-generator.js +75 -14
- package/bin/lib/service-setup.js +272 -126
- package/package.json +1 -1
- package/template/base/js/.eslintrc.json +13 -0
- package/template/base/js/.prettierrc +7 -0
- package/template/base/js/eslint.config.js +31 -0
- package/template/base/js/package.json +28 -0
- package/template/base/js/src/app.js +15 -0
- package/template/base/js/src/config/db.js +8 -0
- package/template/base/js/src/config/env.js +14 -0
- package/template/base/js/src/config/index.js +7 -0
- package/template/base/js/src/middlewares/index.js +9 -0
- package/template/base/js/src/middlewares/method-not-allowed.middleware.js +13 -0
- package/template/base/js/src/middlewares/not-found.middleware.js +10 -0
- package/template/base/js/src/middlewares/root.middleware.js +16 -0
- package/template/base/js/src/modules/index.js +8 -0
- package/template/base/js/src/modules/v1/health/health.controller.js +21 -0
- package/template/base/js/src/modules/v1/health/health.route.js +9 -0
- package/template/base/js/src/modules/v1/health/index.js +5 -0
- package/template/base/js/src/modules/v1/index.js +8 -0
- package/template/base/js/src/routes.js +16 -0
- package/template/base/js/src/server.js +18 -0
- package/template/base/js/src/utils/http-error.js +53 -0
- package/template/base/js/src/utils/index.js +22 -0
- package/template/base/js/src/utils/logger.js +67 -0
- package/template/base/ts/.env.example +5 -0
- package/template/base/ts/.husky/pre-commit +13 -0
- package/template/base/ts/.prettierignore +47 -0
- package/template/base/ts/gitignore +31 -0
- package/template/base/ts/src/app.ts +15 -0
- package/template/base/{src → ts/src}/config/env.ts +10 -10
- package/template/base/{src → ts/src}/middlewares/index.ts +3 -3
- package/template/base/{src → ts/src}/middlewares/method-not-allowed.middleware.ts +16 -17
- package/template/base/{src → ts/src}/middlewares/root.middleware.ts +2 -2
- package/template/base/{src → ts/src}/modules/v1/health/health.controller.ts +18 -18
- package/template/base/{src → ts/src}/modules/v1/health/health.route.ts +9 -9
- package/template/base/{src → ts/src}/modules/v1/health/index.ts +1 -1
- package/template/base/{src → ts/src}/modules/v1/index.ts +8 -8
- package/template/base/{src → ts/src}/routes.ts +15 -15
- package/template/base/{src → ts/src}/utils/http-error.ts +45 -45
- package/template/base/{src → ts/src}/utils/logger.ts +23 -0
- package/template/features/auth/argon2/inject.js +29 -4
- package/template/features/auth/base/inject.js +108 -26
- package/template/features/auth/bcrypt/inject.js +25 -5
- package/template/features/auth/models/user.model.js +24 -0
- package/template/features/auth/modules/auth.controller.js +21 -0
- package/template/features/auth/modules/auth.routes.js +10 -0
- package/template/features/auth/modules/auth.service.js +29 -0
- package/template/features/auth/modules/index.js +1 -0
- package/template/features/auth/utils/jwt.js +12 -0
- package/template/features/cors/inject.js +4 -1
- package/template/features/helmet/inject.js +4 -1
- package/template/features/morgan/inject.js +4 -1
- package/template/features/rate-limit/inject.js +4 -1
- package/template/gateway/js/app.js +42 -0
- package/template/gateway/js/inject.js +31 -0
- package/template/gateway/js/server.js +19 -0
- package/template/gateway/{app.ts → ts/app.ts} +19 -3
- package/template/gateway/ts/inject.js +31 -0
- package/template/gateway/{server.ts → ts/server.ts} +3 -3
- package/template/microservice/docker/.dockerignore +10 -0
- package/template/microservice/docker/Dockerfile +2 -1
- package/template/microservice/docker/docker-compose.yml +0 -1
- package/bin/lib/ts-to-js.js +0 -342
- package/template/base/src/app.ts +0 -8
- package/template/gateway/inject.js +0 -27
- /package/template/base/{.env.example → js/.env.example} +0 -0
- /package/template/base/{.husky → js/.husky}/pre-commit +0 -0
- /package/template/base/{.prettierignore → js/.prettierignore} +0 -0
- /package/template/base/{gitignore → js/gitignore} +0 -0
- /package/template/base/{.eslintrc.json → ts/.eslintrc.json} +0 -0
- /package/template/base/{.prettierrc → ts/.prettierrc} +0 -0
- /package/template/base/{eslint.config.js → ts/eslint.config.js} +0 -0
- /package/template/base/{package.json → ts/package.json} +0 -0
- /package/template/base/{src → ts/src}/config/db.ts +0 -0
- /package/template/base/{src → ts/src}/config/index.ts +0 -0
- /package/template/base/{src → ts/src}/middlewares/not-found.middleware.ts +0 -0
- /package/template/base/{src → ts/src}/modules/index.ts +0 -0
- /package/template/base/{src → ts/src}/server.ts +0 -0
- /package/template/base/{src → ts/src}/utils/index.ts +0 -0
- /package/template/base/{tsconfig.json → ts/tsconfig.json} +0 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module.exports = [
|
|
2
|
+
{
|
|
3
|
+
ignores: ["node_modules/**", "dist/**"],
|
|
4
|
+
},
|
|
5
|
+
{
|
|
6
|
+
files: ["src/**/*.js"],
|
|
7
|
+
languageOptions: {
|
|
8
|
+
ecmaVersion: 2021,
|
|
9
|
+
sourceType: "module",
|
|
10
|
+
globals: {
|
|
11
|
+
console: "readonly",
|
|
12
|
+
process: "readonly",
|
|
13
|
+
Buffer: "readonly",
|
|
14
|
+
__dirname: "readonly",
|
|
15
|
+
__filename: "readonly",
|
|
16
|
+
require: "readonly",
|
|
17
|
+
module: "readonly",
|
|
18
|
+
exports: "writable",
|
|
19
|
+
global: "readonly",
|
|
20
|
+
setTimeout: "readonly",
|
|
21
|
+
setInterval: "readonly",
|
|
22
|
+
clearTimeout: "readonly",
|
|
23
|
+
clearInterval: "readonly",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
rules: {
|
|
27
|
+
"no-unused-vars": "warn",
|
|
28
|
+
"no-undef": "error",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0.0",
|
|
3
|
+
"description": "",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "nodemon --exec node src/server.js",
|
|
7
|
+
"start": "node src/server.js",
|
|
8
|
+
"lint": "eslint \"src/**/*.js\"",
|
|
9
|
+
"format": "prettier --write \"src/**/*.{js,json}\"",
|
|
10
|
+
"check-format": "prettier --check \"src/**/*.{js,json}\"",
|
|
11
|
+
"prepare": "husky"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [],
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"type": "commonjs",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"dotenv": "^16.3.1",
|
|
19
|
+
"express": "^5.2.1"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"eslint": "^9.39.2",
|
|
23
|
+
"eslint-config-prettier": "^10.1.8",
|
|
24
|
+
"husky": "^9.1.7",
|
|
25
|
+
"nodemon": "^3.0.2",
|
|
26
|
+
"prettier": "^3.7.4"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const express = require("express");
|
|
2
|
+
const router = require("./routes");
|
|
3
|
+
/*__IMPORTS__*/
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
// Parse JSON request bodies
|
|
8
|
+
app.use(express.json());
|
|
9
|
+
|
|
10
|
+
/*__MIDDLEWARE__*/
|
|
11
|
+
|
|
12
|
+
// Connect routes
|
|
13
|
+
app.use(router);
|
|
14
|
+
|
|
15
|
+
module.exports = app;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const methodNotAllowedHandler = require("./method-not-allowed.middleware");
|
|
2
|
+
const { notFound } = require("./not-found.middleware");
|
|
3
|
+
const { rootHandler } = require("./root.middleware");
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
methodNotAllowedHandler,
|
|
7
|
+
notFound,
|
|
8
|
+
rootHandler,
|
|
9
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const methodNotAllowed = (allowedMethods) => (req, res, next) => {
|
|
2
|
+
if (!allowedMethods.includes(req.method)) {
|
|
3
|
+
res.set("Allow", allowedMethods.join(", "));
|
|
4
|
+
return res.status(405).json({
|
|
5
|
+
status: "error",
|
|
6
|
+
message: `Method ${req.method} not allowed for ${req.originalUrl}`,
|
|
7
|
+
allowed: allowedMethods,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
next();
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
module.exports = methodNotAllowed;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const rootHandler = (_, res) => {
|
|
2
|
+
res.json({
|
|
3
|
+
name: "/*__PROJECT_NAME__*/",
|
|
4
|
+
type: "/*__PROJECT_TYPE__*/",
|
|
5
|
+
version: "1.0.0",
|
|
6
|
+
status: "running",
|
|
7
|
+
endpoints: {
|
|
8
|
+
health: "/api/v1/health",
|
|
9
|
+
/*__AUTH_ENDPOINT__*/
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
module.exports = {
|
|
15
|
+
rootHandler,
|
|
16
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const { logger } = require("../../../utils");
|
|
2
|
+
|
|
3
|
+
const healthCheck = async (_, res) => {
|
|
4
|
+
logger.info("Health", "healthy");
|
|
5
|
+
|
|
6
|
+
return res.status(200).json({
|
|
7
|
+
status: "healthy",
|
|
8
|
+
uptime: process.uptime(),
|
|
9
|
+
timestamp: new Date().toISOString(),
|
|
10
|
+
services: {
|
|
11
|
+
memory: {
|
|
12
|
+
rss: process.memoryUsage().rss,
|
|
13
|
+
heapUsed: process.memoryUsage().heapUsed,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
module.exports = {
|
|
20
|
+
healthCheck
|
|
21
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const { Router } = require("express");
|
|
2
|
+
const { healthCheck } = require("./health.controller");
|
|
3
|
+
const { methodNotAllowedHandler } = require("../../../middlewares");
|
|
4
|
+
|
|
5
|
+
const router = Router();
|
|
6
|
+
router.use(methodNotAllowedHandler(["GET"]));
|
|
7
|
+
router.get("/", healthCheck);
|
|
8
|
+
|
|
9
|
+
module.exports = router;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const { Router } = require("express");
|
|
2
|
+
const modulesRouter = require("./modules");
|
|
3
|
+
const { notFound, rootHandler } = require("./middlewares");
|
|
4
|
+
|
|
5
|
+
const router = Router();
|
|
6
|
+
|
|
7
|
+
// Root endpoint
|
|
8
|
+
router.get("/", rootHandler);
|
|
9
|
+
|
|
10
|
+
router.use("/api", modulesRouter);
|
|
11
|
+
|
|
12
|
+
// 404 handler - must be last
|
|
13
|
+
router.use(notFound);
|
|
14
|
+
|
|
15
|
+
module.exports = router;
|
|
16
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const app = require("./app");
|
|
2
|
+
const { ENV/*__DB_IMPORT__*/ } = require("./config");
|
|
3
|
+
const { logger } = require("./utils");
|
|
4
|
+
|
|
5
|
+
const PORT = ENV.PORT || 3000;
|
|
6
|
+
|
|
7
|
+
const startServer = async () => {
|
|
8
|
+
/*__DB_CONNECT__*/
|
|
9
|
+
|
|
10
|
+
app.listen(PORT, () => {
|
|
11
|
+
logger.info("Server", `Server is running on port ${PORT}`);
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
startServer().catch((error) => {
|
|
16
|
+
logger.error("Server", "Failed to start server", error);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
class HttpError extends Error {
|
|
2
|
+
constructor(status, message) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.status = status;
|
|
5
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
class BadRequestError extends HttpError {
|
|
10
|
+
constructor(message = "Bad Request") {
|
|
11
|
+
super(400, message);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
class UnauthorizedError extends HttpError {
|
|
16
|
+
constructor(message = "Unauthorized") {
|
|
17
|
+
super(401, message);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
class ForbiddenError extends HttpError {
|
|
22
|
+
constructor(message = "Forbidden") {
|
|
23
|
+
super(403, message);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
class NotFoundError extends HttpError {
|
|
28
|
+
constructor(message = "Not Found") {
|
|
29
|
+
super(404, message);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class ConflictError extends HttpError {
|
|
34
|
+
constructor(message = "Conflict") {
|
|
35
|
+
super(409, message);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
class InternalServerError extends HttpError {
|
|
40
|
+
constructor(message = "Internal Server Error") {
|
|
41
|
+
super(500, message);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
HttpError,
|
|
47
|
+
BadRequestError,
|
|
48
|
+
UnauthorizedError,
|
|
49
|
+
ForbiddenError,
|
|
50
|
+
NotFoundError,
|
|
51
|
+
ConflictError,
|
|
52
|
+
InternalServerError,
|
|
53
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const {
|
|
2
|
+
HttpError,
|
|
3
|
+
BadRequestError,
|
|
4
|
+
UnauthorizedError,
|
|
5
|
+
ForbiddenError,
|
|
6
|
+
NotFoundError,
|
|
7
|
+
ConflictError,
|
|
8
|
+
InternalServerError,
|
|
9
|
+
} = require("./http-error");
|
|
10
|
+
|
|
11
|
+
const logger = require("./logger");
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
HttpError,
|
|
15
|
+
BadRequestError,
|
|
16
|
+
UnauthorizedError,
|
|
17
|
+
ForbiddenError,
|
|
18
|
+
NotFoundError,
|
|
19
|
+
ConflictError,
|
|
20
|
+
InternalServerError,
|
|
21
|
+
logger,
|
|
22
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const { ENV } = require("../config/env");
|
|
2
|
+
// ANSI color codes for terminal output
|
|
3
|
+
const colors = {
|
|
4
|
+
reset: "\x1b[0m",
|
|
5
|
+
blue: "\x1b[34m",
|
|
6
|
+
cyan: "\x1b[36m",
|
|
7
|
+
yellow: "\x1b[33m",
|
|
8
|
+
red: "\x1b[31m",
|
|
9
|
+
bold: "\x1b[1m",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function format(tag, color) {
|
|
13
|
+
return `${color}${colors.bold}[${tag}]${colors.reset}`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getEnvironment() {
|
|
17
|
+
return ENV.NODE_ENV === "development" || ENV.NODE_ENV === "staging"
|
|
18
|
+
? "development"
|
|
19
|
+
: ENV.NODE_ENV;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
console.log(
|
|
23
|
+
format("logger", colors.blue),
|
|
24
|
+
`Logger initialized for ${getEnvironment()} environment.`,
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const requiredKeys = ENV && Object.keys(ENV).length ? Object.keys(ENV) : [];
|
|
28
|
+
|
|
29
|
+
const missing = requiredKeys.filter(
|
|
30
|
+
(k) => ENV == null || ENV[k] === undefined || ENV[k] === "",
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
if (missing.length === requiredKeys.length) {
|
|
34
|
+
console.warn(
|
|
35
|
+
format("logger", colors.yellow),
|
|
36
|
+
"ENV values missing — make sure to set up your environment variables correctly.",
|
|
37
|
+
);
|
|
38
|
+
} else if (missing.length > 0) {
|
|
39
|
+
console.warn(
|
|
40
|
+
format("logger", colors.yellow),
|
|
41
|
+
`Missing ENV keys: ${missing.join(", ")}`,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const logger = {
|
|
46
|
+
log(tag, ...args) {
|
|
47
|
+
if (getEnvironment() !== "development") return;
|
|
48
|
+
console.log(format(tag, colors.blue), ...args);
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
info(tag, ...args) {
|
|
52
|
+
if (getEnvironment() !== "development") return;
|
|
53
|
+
console.info(format(tag, colors.cyan), ...args);
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
warn(tag, ...args) {
|
|
57
|
+
if (getEnvironment() !== "development") return;
|
|
58
|
+
console.warn(format(tag, colors.yellow), ...args);
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
error(tag, ...args) {
|
|
62
|
+
if (getEnvironment() !== "development") return;
|
|
63
|
+
console.error(format(tag, colors.red), ...args);
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
module.exports = logger;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
|
2
|
+
|
|
3
|
+
# dependencies
|
|
4
|
+
/node_modules
|
|
5
|
+
/.pnp
|
|
6
|
+
.pnp.js
|
|
7
|
+
.yarn/install-state.gz
|
|
8
|
+
|
|
9
|
+
# testing
|
|
10
|
+
/coverage
|
|
11
|
+
|
|
12
|
+
# next.js
|
|
13
|
+
/.next/
|
|
14
|
+
/out/
|
|
15
|
+
.next/
|
|
16
|
+
|
|
17
|
+
# production
|
|
18
|
+
/build
|
|
19
|
+
|
|
20
|
+
# misc
|
|
21
|
+
.DS_Store
|
|
22
|
+
*.pem
|
|
23
|
+
|
|
24
|
+
# debug
|
|
25
|
+
npm-debug.log*
|
|
26
|
+
yarn-debug.log*
|
|
27
|
+
yarn-error.log*
|
|
28
|
+
|
|
29
|
+
# local env files
|
|
30
|
+
.env*.local
|
|
31
|
+
|
|
32
|
+
# vercel
|
|
33
|
+
.vercel
|
|
34
|
+
|
|
35
|
+
# typescript
|
|
36
|
+
*.tsbuildinfo
|
|
37
|
+
next-env.d.ts
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
./dist
|
|
41
|
+
|
|
42
|
+
/*.yml
|
|
43
|
+
/*.yaml
|
|
44
|
+
/*.md
|
|
45
|
+
/*.json
|
|
46
|
+
README.md
|
|
47
|
+
eslint.config.ts
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Dependencies
|
|
2
|
+
node_modules/
|
|
3
|
+
package-lock.json
|
|
4
|
+
|
|
5
|
+
# Build output
|
|
6
|
+
dist/
|
|
7
|
+
|
|
8
|
+
# Environment variables
|
|
9
|
+
.env
|
|
10
|
+
.env.local
|
|
11
|
+
.env.*.local
|
|
12
|
+
|
|
13
|
+
# Logs
|
|
14
|
+
logs/
|
|
15
|
+
*.log
|
|
16
|
+
npm-debug.log*
|
|
17
|
+
yarn-debug.log*
|
|
18
|
+
|
|
19
|
+
# ESLint
|
|
20
|
+
.eslintcache
|
|
21
|
+
|
|
22
|
+
# OS files
|
|
23
|
+
.DS_Store
|
|
24
|
+
Thumbs.db
|
|
25
|
+
|
|
26
|
+
# IDE
|
|
27
|
+
.vscode/
|
|
28
|
+
.idea/
|
|
29
|
+
*.swp
|
|
30
|
+
*.swo
|
|
31
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import router from "./routes";
|
|
3
|
+
/*__IMPORTS__*/
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
// Parse JSON request bodies
|
|
8
|
+
app.use(express.json());
|
|
9
|
+
|
|
10
|
+
/*__MIDDLEWARE__*/
|
|
11
|
+
|
|
12
|
+
// Connect routes
|
|
13
|
+
app.use(router);
|
|
14
|
+
|
|
15
|
+
export default app;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import dotenv from "dotenv";
|
|
2
|
-
dotenv.config();
|
|
3
|
-
|
|
4
|
-
export const ENV = {
|
|
5
|
-
PORT: process.env.PORT!,
|
|
6
|
-
/*__ALLOWED_ORIGIN__*/
|
|
7
|
-
NODE_ENV: process.env.NODE_ENV!,
|
|
8
|
-
/*__MONGO_URI__*/
|
|
9
|
-
/*__JWT_SECRET__*/
|
|
10
|
-
};
|
|
1
|
+
import dotenv from "dotenv";
|
|
2
|
+
dotenv.config();
|
|
3
|
+
|
|
4
|
+
export const ENV = {
|
|
5
|
+
PORT: process.env.PORT!,
|
|
6
|
+
/*__ALLOWED_ORIGIN__*/
|
|
7
|
+
NODE_ENV: process.env.NODE_ENV!,
|
|
8
|
+
/*__MONGO_URI__*/
|
|
9
|
+
/*__JWT_SECRET__*/
|
|
10
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { default as methodNotAllowedHandler } from "./method-not-allowed.middleware";
|
|
2
|
-
export { notFound } from "./not-found.middleware";
|
|
3
|
-
export { rootHandler } from "./root.middleware";
|
|
1
|
+
export { default as methodNotAllowedHandler } from "./method-not-allowed.middleware";
|
|
2
|
+
export { notFound } from "./not-found.middleware";
|
|
3
|
+
export { rootHandler } from "./root.middleware";
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
res.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export default methodNotAllowed;
|
|
1
|
+
import { Request, Response, NextFunction } from "express";
|
|
2
|
+
|
|
3
|
+
const methodNotAllowed =
|
|
4
|
+
(allowedMethods: string[]) => (req: Request, res: Response, next: NextFunction) => {
|
|
5
|
+
if (!allowedMethods.includes(req.method)) {
|
|
6
|
+
res.set("Allow", allowedMethods.join(", "));
|
|
7
|
+
return res.status(405).json({
|
|
8
|
+
status: "error",
|
|
9
|
+
message: `Method ${req.method} not allowed for ${req.originalUrl}`,
|
|
10
|
+
allowed: allowedMethods,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
next();
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default methodNotAllowed;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Request, Response } from "express";
|
|
2
2
|
|
|
3
|
-
export const rootHandler = (
|
|
3
|
+
export const rootHandler = (_req: Request, res: Response) => {
|
|
4
4
|
res.json({
|
|
5
5
|
name: "/*__PROJECT_NAME__*/",
|
|
6
6
|
type: "/*__PROJECT_TYPE__*/",
|
|
7
7
|
version: "1.0.0",
|
|
8
8
|
status: "running",
|
|
9
9
|
endpoints: {
|
|
10
|
-
health: "/v1/health",
|
|
10
|
+
health: "/api/v1/health",
|
|
11
11
|
/*__AUTH_ENDPOINT__*/
|
|
12
12
|
},
|
|
13
13
|
});
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { Request, Response } from "express";
|
|
2
|
-
import { logger } from "@/utils";
|
|
3
|
-
|
|
4
|
-
export const healthCheck = async (_: Request, res: Response) => {
|
|
5
|
-
logger.info("Health", "healthy");
|
|
6
|
-
|
|
7
|
-
return res.status(200).json({
|
|
8
|
-
status: "healthy",
|
|
9
|
-
uptime: process.uptime(),
|
|
10
|
-
timestamp: new Date().toISOString(),
|
|
11
|
-
services: {
|
|
12
|
-
memory: {
|
|
13
|
-
rss: process.memoryUsage().rss,
|
|
14
|
-
heapUsed: process.memoryUsage().heapUsed,
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
};
|
|
1
|
+
import { Request, Response } from "express";
|
|
2
|
+
import { logger } from "@/utils";
|
|
3
|
+
|
|
4
|
+
export const healthCheck = async (_: Request, res: Response) => {
|
|
5
|
+
logger.info("Health", "healthy");
|
|
6
|
+
|
|
7
|
+
return res.status(200).json({
|
|
8
|
+
status: "healthy",
|
|
9
|
+
uptime: process.uptime(),
|
|
10
|
+
timestamp: new Date().toISOString(),
|
|
11
|
+
services: {
|
|
12
|
+
memory: {
|
|
13
|
+
rss: process.memoryUsage().rss,
|
|
14
|
+
heapUsed: process.memoryUsage().heapUsed,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Router } from "express";
|
|
2
|
-
import { healthCheck } from "./health.controller";
|
|
3
|
-
import { methodNotAllowedHandler } from "@/middlewares";
|
|
4
|
-
|
|
5
|
-
const router = Router();
|
|
6
|
-
router.use(methodNotAllowedHandler(["GET"]));
|
|
7
|
-
router.get("/", healthCheck);
|
|
8
|
-
|
|
9
|
-
export default router;
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { healthCheck } from "./health.controller";
|
|
3
|
+
import { methodNotAllowedHandler } from "@/middlewares";
|
|
4
|
+
|
|
5
|
+
const router = Router();
|
|
6
|
+
router.use(methodNotAllowedHandler(["GET"]));
|
|
7
|
+
router.get("/", healthCheck);
|
|
8
|
+
|
|
9
|
+
export default router;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default as healthRoutes } from "./health.route";
|
|
1
|
+
export { default as healthRoutes } from "./health.route";
|