Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Backend/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PORT=
CORS_ORIGIN=
27 changes: 27 additions & 0 deletions Backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

package-lock.json
.env
34 changes: 34 additions & 0 deletions Backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "backend",
"version": "1.0.0",
"description": "Backend for Project-Assemble",
"main": "index.js",
"type": "module",
"scripts": {
"dev": "nodemon -r dotenv/config --experimental-json-modules src/index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/TheGradients/Assemble.git"
},
"keywords": [
"node",
"javascript",
"backend"
],
"author": "TheGradients",
"license": "ISC",
"bugs": {
"url": "https://github.com/TheGradients/Assemble/issues"
},
"homepage": "https://github.com/TheGradients/Assemble#readme",
"dependencies": {
"body-parser": "^1.20.2",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"mongoose": "^8.4.4",
"nodemon": "^3.1.4"
}
}
28 changes: 28 additions & 0 deletions Backend/src/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import express from "express";
import cors from "cors";
import cookieParser from "cookie-parser";

const app = express();

app.use(cors({
origin: process.env.CORS_ORIGIN,
credentials: true
}));

app.use(express.json({
limit: "16kb"
}));

app.use(express.urlencoded({
extended: true,
limit: "16kb"
}));

app.use(cookieParser());

// HEALTH CHECK ROUTE
import healthRouter from "./routes/healthcheck.routes.js";

app.use("/api/v1", healthRouter);

export default app;
File renamed without changes.
19 changes: 19 additions & 0 deletions Backend/src/controllers/healthcheck.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import asyncHandler from "../utils/asyncHandler.js";
import ApiResponse from "../utils/ApiResponse.js";
import ApiError from "../utils/ApiError.js";

const healthCheck = asyncHandler( async (req, res) => {
return res
.status(200)
.json(
new ApiResponse(
200,
[],
"API Is Running Good!"
)
);
});

export {
healthCheck
};
Empty file added Backend/src/db/.gitkeep
Empty file.
10 changes: 10 additions & 0 deletions Backend/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import dotenv from "dotenv";
import app from "./app.js";

dotenv.config({
path: './env'
});

app.listen(process.env.PORT || 8000, () => {
console.log(`App Started On Port: ${process.env.PORT}`);;
});
Empty file.
Empty file added Backend/src/models/.gitkeep
Empty file.
8 changes: 8 additions & 0 deletions Backend/src/routes/healthcheck.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Router } from "express";
import { healthCheck } from "../controllers/healthCheck.controller.js";

const router = Router();

router.route("/health-check").get(healthCheck);

export default router;
23 changes: 23 additions & 0 deletions Backend/src/utils/ApiError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class ApiError extends Error {
constructor(
statusCode,
message = "Something Went Wrong!",
errors = [],
stack
) {
super(message)
this.statusCode = statusCode
this.data = []
this.message = message
this.success = false
this.errors = errors

if (stack) {
this.stack = stack
} else {
Error.captureStackTrace(this, this.constructor)
}
}
}

export default ApiError;
14 changes: 14 additions & 0 deletions Backend/src/utils/ApiResponse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class ApiResponse {
constructor(
statusCode,
data,
message = "Success!"
) {
this.statusCode = statusCode
this.data = data
this.message = message
this.success = statusCode < 400
}
}

export default ApiResponse;
9 changes: 9 additions & 0 deletions Backend/src/utils/asyncHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const asyncHanlder = (requestHandler) => {
return (req, res, next) => {
Promise
.resolve(requestHandler(req, res, next))
.catch((err) => next(err));
}
};

export default asyncHanlder;