Skip to content

Commit c09f39f

Browse files
committed
updated routes
1 parent f124fcd commit c09f39f

25 files changed

+469
-453
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ test
4848
*.ARCHIVES
4949
*.ZIP
5050
.env
51+
52+
claudeConfig.md

README.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ A Node.js/Express backend server for the WTWR application with user authenticati
1010
## 🚀 Quick Start
1111

1212
### Prerequisites
13+
1314
- Node.js (v22+)
1415
- MongoDB
1516
- Git
@@ -73,20 +74,21 @@ npm run dev
7374

7475
## 🛠️ Available Scripts
7576

76-
| Command | Description |
77-
|---------|-------------|
78-
| `npm start` | Start production server |
79-
| `npm run dev` | Start development server with nodemon |
80-
| `npm run prebuild` | Clean install dependencies |
81-
| `npm run seedUser` | Seed database with test users |
82-
| `npm run seedClothing` | Seed database with clothing items |
83-
| `npm run lint` | Run ESLint |
84-
| `npm run db:start` | Start MongoDB and open shell |
85-
| `npm run db:stop` | Stop MongoDB |
77+
| Command | Description |
78+
| ---------------------- | ------------------------------------- |
79+
| `npm start` | Start production server |
80+
| `npm run dev` | Start development server with nodemon |
81+
| `npm run prebuild` | Clean install dependencies |
82+
| `npm run seedUser` | Seed database with test users |
83+
| `npm run seedClothing` | Seed database with clothing items |
84+
| `npm run lint` | Run ESLint |
85+
| `npm run db:start` | Start MongoDB and open shell |
86+
| `npm run db:stop` | Stop MongoDB |
8687

8788
## 🗄️ Database Setup
8889

8990
### Start MongoDB
91+
9092
```bash
9193
# Start service
9294
brew services start mongodb-community
@@ -99,6 +101,7 @@ mongosh
99101
```
100102

101103
### Seed Database
104+
102105
```bash
103106
# Create test users
104107
npm run seedUser
@@ -120,14 +123,17 @@ NODE_ENV=development
120123
## 📚 API Endpoints
121124

122125
### Authentication
126+
123127
- `POST /signin` - User login
124128
- `POST /signup` - User registration
125129

126130
### Users
131+
127132
- `GET /users/me` - Get current user
128133
- `PATCH /users/me` - Update user profile
129134

130135
### Clothing Items
136+
131137
- `GET /items` - Get all clothing items
132138
- `POST /items` - Create new clothing item
133139
- `DELETE /items/:itemId` - Delete clothing item
@@ -151,6 +157,7 @@ NODE_ENV=development
151157
## 🚀 Deployment
152158

153159
The application is deployed using:
160+
154161
- **Server:** Google Cloud VM
155162
- **Process Manager:** PM2
156163
- **Web Server:** Nginx
@@ -160,12 +167,15 @@ The application is deployed using:
160167
## 🧪 Testing
161168

162169
### Crash Recovery Test
170+
163171
The application includes PM2 auto-recovery. Test with:
172+
164173
```bash
165174
curl https://api.testwtwr.jumpingcrab.com/crash-test
166175
```
167176

168177
### Development Testing
178+
169179
```bash
170180
# Test user credentials
171181
Email: joshtarget@example.com
@@ -175,6 +185,7 @@ Password: mypassword123
175185
## 🛠️ Troubleshooting
176186

177187
### MongoDB Issues
188+
178189
```bash
179190
# Restart MongoDB
180191
brew services restart mongodb-community
@@ -184,6 +195,7 @@ brew services list | grep mongodb
184195
```
185196

186197
### PM2 Issues
198+
187199
```bash
188200
# Restart application
189201
pm2 restart app --update-env
@@ -208,4 +220,4 @@ Currently on Sprint 15 - Full deployment with authentication and security featur
208220
---
209221

210222
**Author:** Joshua Zimmerman
211-
**License:** ISC
223+
**License:** ISC

app.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const express = require("express");
2-
const { errors } = require('celebrate');
2+
const { errors } = require("celebrate");
33
const mongoose = require("mongoose");
44
const cors = require("cors");
5-
const { requestLogger, errorLogger } = require('./middlewares/logger');
6-
const errorHandler = require('./middlewares/errorHandler');
7-
require('dotenv').config();
5+
const { requestLogger, errorLogger } = require("./middlewares/logger");
6+
const errorHandler = require("./middlewares/errorHandler");
7+
require("dotenv").config();
88

9-
mongoose.set('strictQuery', false);
9+
mongoose.set("strictQuery", false);
1010

1111
const routes = require("./routes");
1212

@@ -17,29 +17,31 @@ const app = express();
1717
const { PORT = 3001, BASE_PATH = "http://localhost" } = process.env;
1818

1919
mongoose
20-
.connect("mongodb://127.0.0.1:27017/wtwr_db")
21-
.then(() => {
22-
console.log("Connected to MongoDB");
23-
})
24-
.catch((err) => console.error(err));
20+
.connect("mongodb://127.0.0.1:27017/wtwr_db")
21+
.then(() => {
22+
console.log("Connected to MongoDB");
23+
})
24+
.catch((err) => console.error(err));
2525

2626
app.use(express.json());
27-
app.use(cors({
27+
app.use(
28+
cors({
2829
origin: [
29-
'https://testwtwr.jumpingcrab.com', // Original domain
30-
'https://www.testwtwr.jumpingcrab.com', // With www subdomain
31-
'http://localhost:3000' // Development
30+
"https://testwtwr.jumpingcrab.com", // Original domain
31+
"https://www.testwtwr.jumpingcrab.com", // With www subdomain
32+
"http://localhost:3000", // Development
3233
],
33-
credentials: true
34-
}));
34+
credentials: true,
35+
}),
36+
);
3537

3638
// Place requestLogger BEFORE all routes
3739
app.use(requestLogger);
3840

39-
app.get('/crash-test', () => {
40-
setTimeout(() => {
41-
throw new Error('Server will crash now');
42-
}, 0);
41+
app.get("/crash-test", () => {
42+
setTimeout(() => {
43+
throw new Error("Server will crash now");
44+
}, 0);
4345
});
4446

4547
app.post("/signin", validateAuth, login);
@@ -53,5 +55,5 @@ app.use(errors());
5355
app.use(errorHandler);
5456

5557
app.listen(PORT, () => {
56-
console.log(`Server running on ${BASE_PATH}:${PORT}`);
57-
});
58+
console.log(`Server running on ${BASE_PATH}:${PORT}`);
59+
});

0 commit comments

Comments
 (0)