Skip to content

Commit d6a5235

Browse files
Merge branch 'development' into 51-create_CRUD_operations_for_group_model
2 parents 0dc8569 + d632506 commit d6a5235

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+7011
-2435
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
coverage
3+
logs
4+
.env

.eslintrc.cjs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es2021: true,
5+
jest: true
6+
},
7+
extends: "airbnb-base",
8+
overrides: [],
9+
parserOptions: {
10+
ecmaVersion: "latest",
11+
sourceType: "module",
12+
},
13+
rules: {
14+
"linebreak-style": 0,
15+
"no-console": 0,
16+
semi: ["error", "always"],
17+
quotes: ["error", "double"],
18+
"import/prefer-default-export": "off"
19+
},
20+
"settings": {
21+
"import/resolver": {
22+
"alias": {
23+
"map": [
24+
["#app", "./app.js"],
25+
["#util", "./util.js"],
26+
["#constant", "./constant.js"],
27+
["#routes", "./routes"],
28+
["#models", "./models"],
29+
["#middleware", "./middleware"],
30+
["#controller", "./controller"],
31+
["#services", "./services"],
32+
["#error", "./error"]
33+
],
34+
"extensions": [".js"]
35+
}
36+
}
37+
}
38+
};

.eslintrc.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

.github/pull_request_template.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Description
2+
Briefly describe the changes made in this pull request.
3+
4+
## Fixes
5+
Specify the related issues or tickets that this pull request fixes (e.g., Fixes #123).
6+
7+
## Checklist
8+
<!-- add x inside brackets for ticking the checkbox eg - [x] -->
9+
- [ ] Code follows project's style guidelines.
10+
- [ ] Changes are documented appropriately.
11+
12+
## Notes
13+
Add any additional notes or context that might be useful for reviewers.
14+
15+
16+
17+
#### (PS → Make Sure Pull request title is meaningful.)

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM node:18.15.0
2+
3+
WORKDIR /usr/src/app
4+
5+
COPY package*.json ./
6+
7+
RUN npm ci
8+
9+
COPY . .
10+
11+
EXPOSE 3500
12+
CMD ["npm", "run", "start"]
13+
14+
15+

app.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1-
const express = require('express');
2-
const path = require('path');
3-
const logger = require('morgan');
4-
const cookieParser = require('cookie-parser');
5-
const cors = require('cors');
6-
7-
const indexRouter = require('./routes/index');
8-
const usersRouter = require('./routes/users');
9-
const authRouter = require('./routes/auth');
1+
import express from "express";
2+
import path, { dirname } from "path";
3+
import morgan from "morgan";
4+
import cookieParser from "cookie-parser";
5+
import cors from "cors";
6+
import { fileURLToPath } from "url";
7+
import { logger } from "#util";
8+
import indexRouter from "#routes/index";
9+
import usersRouter from "#routes/users";
10+
import authRouter from "#routes/auth";
1011

1112
const app = express();
13+
const currDirName = dirname(fileURLToPath(import.meta.url));
14+
15+
app.use(morgan(
16+
":remote-addr - :remote-user \":method :url HTTP/:http-version\" :status \":referrer\" \":user-agent\"",
17+
{ stream: logger.stream },
18+
));
1219

1320
app.use(cors());
14-
app.use(logger('dev'));
1521
app.use(express.json());
1622
app.use(express.urlencoded({ extended: false }));
1723
app.use(cookieParser());
18-
app.use(express.static(path.join(__dirname, 'public')));
24+
app.use(express.static(path.join(currDirName, "public")));
1925

20-
app.use('/', indexRouter);
21-
app.use('/users', usersRouter);
22-
app.use('/auth', authRouter);
26+
app.use("/", indexRouter);
27+
app.use("/users", usersRouter);
28+
app.use("/auth", authRouter);
2329

24-
module.exports = app;
30+
export default app;

bin/www

Lines changed: 0 additions & 93 deletions
This file was deleted.

bin/www.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
import http from "http";
8+
import debug from "debug";// ("api:server");
9+
import dotenv from "dotenv";
10+
import app from "#app";
11+
import { logger } from "#util";
12+
13+
dotenv.config();
14+
15+
/**
16+
* Normalize a port into a number, string, or false.
17+
*/
18+
19+
function normalizePort(val) {
20+
const port = parseInt(val, 10);
21+
22+
if (Number.isNaN(port)) {
23+
// named pipe
24+
return val;
25+
}
26+
27+
if (port >= 0) {
28+
// port number
29+
return port;
30+
}
31+
32+
return false;
33+
}
34+
35+
/**
36+
* Get port from environment and store in Express.
37+
*/
38+
39+
const port = normalizePort(process.env.PORT || "3000");
40+
app.set("port", port);
41+
42+
/**
43+
* Create HTTP server.
44+
*/
45+
46+
const server = http.createServer(app);
47+
48+
/**
49+
* Event listener for HTTP server "error" event.
50+
*/
51+
52+
function onError(error) {
53+
if (error.syscall !== "listen") {
54+
throw error;
55+
}
56+
57+
const bind = typeof port === "string"
58+
? `Pipe ${port}`
59+
: `Port ${port}`;
60+
61+
// handle specific listen errors with friendly messages
62+
switch (error.code) {
63+
case "EACCES":
64+
logger.error(`${bind} requires elevated privileges`);
65+
process.exit(1);
66+
break;
67+
case "EADDRINUSE":
68+
logger.error(`${bind} is already in use`);
69+
process.exit(1);
70+
break;
71+
default:
72+
throw error;
73+
}
74+
}
75+
76+
/**
77+
* Event listener for HTTP server "listening" event.
78+
*/
79+
80+
function onListening() {
81+
const addr = server.address();
82+
const bind = typeof addr === "string"
83+
? `pipe ${addr}`
84+
: `port ${addr.port}`;
85+
debug(`Listening on ${bind}`);
86+
}
87+
88+
/**
89+
* Listen on provided port, on all network interfaces.
90+
*/
91+
92+
server.listen(port);
93+
server.on("error", onError);
94+
server.on("listening", onListening);

constant.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const logLevel = {
2+
local: "silly",
3+
dev: "debug",
4+
prod: "info",
5+
};

0 commit comments

Comments
 (0)