Spaces:
Sleeping
Sleeping
Commit ·
848548d
1
Parent(s): b4f734e
Upload 5 files
Browse files- .dockerignore +2 -0
- .gitignore +24 -0
- Dockerfile +20 -0
- index.js +55 -0
- package.json +22 -0
.dockerignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
node_modules
|
| 2 |
+
npm-debug.log
|
.gitignore
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Logs
|
| 2 |
+
logs
|
| 3 |
+
*.log
|
| 4 |
+
npm-debug.log*
|
| 5 |
+
yarn-debug.log*
|
| 6 |
+
yarn-error.log*
|
| 7 |
+
pnpm-debug.log*
|
| 8 |
+
lerna-debug.log*
|
| 9 |
+
|
| 10 |
+
node_modules
|
| 11 |
+
dist
|
| 12 |
+
dist-ssr
|
| 13 |
+
*.local
|
| 14 |
+
|
| 15 |
+
# Editor directories and files
|
| 16 |
+
.vscode/*
|
| 17 |
+
!.vscode/extensions.json
|
| 18 |
+
.idea
|
| 19 |
+
.DS_Store
|
| 20 |
+
*.suo
|
| 21 |
+
*.ntvs*
|
| 22 |
+
*.njsproj
|
| 23 |
+
*.sln
|
| 24 |
+
*.sw?
|
Dockerfile
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use Node.js LTS image
|
| 2 |
+
FROM node:20-alpine
|
| 3 |
+
|
| 4 |
+
# Set working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy package.json and package-lock.json
|
| 8 |
+
COPY package*.json ./
|
| 9 |
+
|
| 10 |
+
# Install dependencies
|
| 11 |
+
RUN npm install --production
|
| 12 |
+
|
| 13 |
+
# Copy source code
|
| 14 |
+
COPY . .
|
| 15 |
+
|
| 16 |
+
# Expose the port your app runs on
|
| 17 |
+
EXPOSE 5000
|
| 18 |
+
|
| 19 |
+
# Start the app
|
| 20 |
+
CMD ["node", "index.js"]
|
index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import express from 'express';
|
| 2 |
+
import dotenv from 'dotenv';
|
| 3 |
+
import cors from 'cors';
|
| 4 |
+
import morgan from 'morgan';
|
| 5 |
+
import compression from 'compression';
|
| 6 |
+
import customersRoutes from "./routes/customerRoutes.js";
|
| 7 |
+
import invoicesRoutes from "./routes/invoiceRoutes.js";
|
| 8 |
+
import reportsRoutes from "./routes/reportRoutes.js";
|
| 9 |
+
import productRoutes from "./routes/productRoutes.js";
|
| 10 |
+
import expenseRoutes from "./routes/expenseRoutes.js";
|
| 11 |
+
import supplierRoutes from "./routes/supplierRoutes.js";
|
| 12 |
+
import authRoutes from "./routes/authRoutes.js";
|
| 13 |
+
import { dbConnection } from './config/database.js';
|
| 14 |
+
|
| 15 |
+
dotenv.config();
|
| 16 |
+
|
| 17 |
+
const app = express();
|
| 18 |
+
dbConnection();
|
| 19 |
+
|
| 20 |
+
const allowedOrigins = [
|
| 21 |
+
'https://salessystem-tau.vercel.app',
|
| 22 |
+
'http://localhost:5173'
|
| 23 |
+
];
|
| 24 |
+
|
| 25 |
+
app.use(cors({
|
| 26 |
+
origin: (origin, callback) => {
|
| 27 |
+
if (!origin || allowedOrigins.includes(origin)) {
|
| 28 |
+
callback(null, true); // allow
|
| 29 |
+
} else {
|
| 30 |
+
callback(new Error('Not allowed by CORS'));
|
| 31 |
+
}
|
| 32 |
+
},
|
| 33 |
+
credentials: true
|
| 34 |
+
}));
|
| 35 |
+
|
| 36 |
+
app.use(compression());
|
| 37 |
+
app.use(express.urlencoded({ extended: true, limit: '15kb' }));
|
| 38 |
+
app.use(express.json({ limit: '15kb' }));
|
| 39 |
+
app.use(morgan('dev'));
|
| 40 |
+
|
| 41 |
+
app.use('/customers', customersRoutes);
|
| 42 |
+
app.use('/invoices', invoicesRoutes);
|
| 43 |
+
app.use('/reports', reportsRoutes);
|
| 44 |
+
app.use('/products', productRoutes);
|
| 45 |
+
app.use('/expenses', expenseRoutes);
|
| 46 |
+
app.use('/suppliers', supplierRoutes);
|
| 47 |
+
app.use('/auth', authRoutes);
|
| 48 |
+
app.get('/', (req, res) => {
|
| 49 |
+
res.status(200).json({ message: 'App Is running' });
|
| 50 |
+
});
|
| 51 |
+
|
| 52 |
+
const PORT = process.env.PORT || 5000;
|
| 53 |
+
app.listen(PORT, () => {
|
| 54 |
+
console.log(`Server running on port ${PORT}`);
|
| 55 |
+
});
|
package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "backend",
|
| 3 |
+
"version": "1.0.0",
|
| 4 |
+
"description": "",
|
| 5 |
+
"main": "index.js",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"start": "nodemon index.js"
|
| 8 |
+
},
|
| 9 |
+
"keywords": [],
|
| 10 |
+
"author": "",
|
| 11 |
+
"license": "ISC",
|
| 12 |
+
"type": "module",
|
| 13 |
+
"dependencies": {
|
| 14 |
+
"compression": "^1.8.1",
|
| 15 |
+
"cors": "^2.8.5",
|
| 16 |
+
"dotenv": "^17.2.3",
|
| 17 |
+
"express": "^5.2.1",
|
| 18 |
+
"mongoose": "^9.0.2",
|
| 19 |
+
"morgan": "^1.10.1",
|
| 20 |
+
"nodemon": "^3.1.11"
|
| 21 |
+
}
|
| 22 |
+
}
|