Skip to content

Commit

Permalink
connected backend with frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
ogeobubu committed Oct 4, 2024
1 parent 8c6b2d8 commit 91730a7
Show file tree
Hide file tree
Showing 8 changed files with 393 additions and 26 deletions.
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"server": "cd src && nodemon --exec ts-node server.ts",
"client": "cd client && yarn run dev",
"dev": "concurrently \"yarn server\" \"yarn client\""
},
"keywords": [],
"author": "",
Expand All @@ -15,6 +17,8 @@
"@types/multer": "^1.4.12",
"@types/node-cron": "^3.0.11",
"@types/sharp": "^0.32.0",
"@types/swagger-ui-express": "^4.1.6",
"dotenv": "^16.4.5",
"express": "^4.21.0",
"mongoose": "^8.6.3",
"multer": "^1.4.5-lts.1",
Expand All @@ -24,5 +28,9 @@
"swagger-ui-express": "^5.0.1",
"ts-node": "^10.9.2",
"typescript": "^5.6.2"
},
"devDependencies": {
"concurrently": "^9.0.1",
"nodemon": "^3.1.7"
}
}
24 changes: 12 additions & 12 deletions src/config/db.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import mongoose from 'mongoose';
import dotenv from 'dotenv';

import dotenv from "dotenv";
dotenv.config();
import mongoose from "mongoose";

const connectDB = async () => {
try {
await mongoose.connect(process.env.MONGO_URI || '', {
useNewUrlParser: true,
useUnifiedTopology: true
});
console.log('MongoDB Connected');
} catch (err) {
console.error('MongoDB connection error:', err);
process.exit(1);
try {
const mongoUri = process.env.MONGO_URI;
if (!mongoUri) {
throw new Error("MONGO_URI is not defined in the environment variables.");
}
await mongoose.connect(mongoUri);
console.log("MongoDB Connected");
} catch (err) {
console.error("MongoDB connection error:", err);
process.exit(1);
}
};

export default connectDB;
2 changes: 1 addition & 1 deletion src/controllers/imageController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const extractImageFeatures = async (filePath: string) => {
const features = {
length: height || 0,
width: width || 0,
color: 'Green' // Example color, can use advanced color extraction
color: 'Green'
};

return features;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/imageProcessing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import sharp from "sharp";
export const processImage = async (imagePath: string) => {
try {
const processedImage = await sharp(imagePath)
.resize(500) // Resize to 500 pixels wide
.webp({ quality: 80 }) // Convert to WebP format with 80% quality
.resize(500)
.webp({ quality: 80 })
.toBuffer();

return processedImage;
Expand Down
18 changes: 12 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": "./",
"paths": {
"*": ["node_modules/*", "typings/*"]
}
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
"include": [
"src/**/*",
"typings/**/*"
]
}
21 changes: 21 additions & 0 deletions typings/swagger-jsdoc.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
declare module "swagger-jsdoc" {
interface SwaggerDefinition {
openapi: string;
info: {
title: string;
version: string;
description: string;
};
servers: Array<{
url: string;
description: string;
}>;
}

interface Options {
swaggerDefinition: SwaggerDefinition;
apis: string[];
}

export default function swaggerJSDoc(options: Options): any;
}
6 changes: 6 additions & 0 deletions typings/swagger-ui-express.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare module 'swagger-ui-express' {
import { RequestHandler } from 'express';

export function serve(): RequestHandler;
export function setup(doc: any, options?: any): RequestHandler;
}
Loading

0 comments on commit 91730a7

Please sign in to comment.