Skip to content

Commit 6eafce2

Browse files
authored
Merge pull request #19 from devxtra-community/shanu
Shanu
2 parents 8a84d16 + b98a341 commit 6eafce2

35 files changed

Lines changed: 14519 additions & 79 deletions

.github/workflows/cicd.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI/CD – Deploy Backend
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Setup SSH
17+
run: |
18+
mkdir -p ~/.ssh
19+
echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_rsa
20+
chmod 600 ~/.ssh/id_rsa
21+
ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts
22+
23+
- name: Deploy to EC2
24+
run: |
25+
ssh -i ~/.ssh/id_rsa ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
26+
cd mysocialcode
27+
git pull origin main
28+
cd backend
29+
pnpm install
30+
pm2 restart all
31+
EOF

.husky/commit-msg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
pnpm exec commitlint --edit $1

.husky/pre-commit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
pnpm format && pnpm --filter backend lint

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
dist
3+
build

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"trailingComma": "all"
5+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This repository contains both the frontend and backend code in a single reposito
88
## Structure
99

1010
mysocialcode/
11+
1112
- frontend/ – Frontend application (Expo / React Native)
1213
- backend/ – Backend API (Node.js / Express)
1314

backend/eslint.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import js from '@eslint/js';
2+
import tseslint from 'typescript-eslint';
3+
4+
export default [
5+
{
6+
ignores: ['dist/**', 'build/**', 'node_modules/**'],
7+
rules: {
8+
'@typescript-eslint/no-unused-vars': [
9+
'error',
10+
{ argsIgnorePattern: '^_' },
11+
],
12+
},
13+
},
14+
js.configs.recommended,
15+
...tseslint.configs.recommended,
16+
];

backend/package.json

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
{
22
"name": "backend",
3-
"version": "1.0.0",
4-
"description": "",
5-
"main": "index.js",
3+
"private": true,
64
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
5+
"dev": "ts-node-dev --respawn --transpile-only src/server.ts",
6+
"build": "tsc",
7+
"start": "node dist/server.js",
8+
"lint": "eslint"
89
},
9-
"keywords": [],
10-
"author": "",
11-
"license": "ISC",
12-
"type": "commonjs"
10+
"dependencies": {
11+
"dotenv": "^17.2.3",
12+
"express": "^5.2.1",
13+
"pg": "^8.16.3",
14+
"pino": "^10.1.0",
15+
"pino-http": "^11.0.0",
16+
"reflect-metadata": "^0.2.2",
17+
"typeorm": "^0.3.28"
18+
},
19+
"devDependencies": {
20+
"@commitlint/cli": "^20.2.0",
21+
"@commitlint/config-conventional": "^20.2.0",
22+
"@eslint/js": "^9.39.2",
23+
"@types/express": "^5.0.6",
24+
"@types/node": "^25.0.3",
25+
"@types/pg": "^8.16.0",
26+
"@typescript-eslint/eslint-plugin": "^8.51.0",
27+
"@typescript-eslint/parser": "^8.51.0",
28+
"eslint": "^9.39.2",
29+
"ts-node-dev": "^2.0.0",
30+
"typescript": "~5.9.3",
31+
"typescript-eslint": "^8.51.0"
32+
}
1333
}

backend/src/app.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import express from 'express';
2+
import { pinoHttp } from 'pino-http';
3+
import { logger } from './utils/logger';
4+
import { notFound } from './middleware/notFound';
5+
import { errorHandler } from './middleware/errorHandler';
6+
import Healthrouter from './routes/health';
7+
const app = express();
8+
app.use(express.json());
9+
app.use(
10+
pinoHttp({ logger, autoLogging: { ignore: (req) => req.url === 'health' } }),
11+
);
12+
app.use('/health', Healthrouter);
13+
app.use(notFound);
14+
app.use(errorHandler);
15+
export default app;

backend/src/data-source.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import 'dotenv/config';
2+
import { DataSource } from 'typeorm';
3+
import { User } from './entities/User';
4+
if (!process.env.DATABASE_URL) {
5+
throw new Error('DATABASE_URL is not defined');
6+
}
7+
export const appDataSouce = new DataSource({
8+
type: 'postgres',
9+
url: process.env.DATABASE_URL,
10+
ssl: {
11+
rejectUnauthorized: false,
12+
},
13+
entities: [User],
14+
synchronize: true,
15+
});

0 commit comments

Comments
 (0)