-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
427 lines (378 loc) · 14.4 KB
/
app.js
File metadata and controls
427 lines (378 loc) · 14.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
import express from 'express';
import {PORT} from './config/env.js';
import userRouter from './routes/user.routes.js';
import authRouter from './routes/auth.routes.js';
import subscriptionRouter from './routes/subscription.routes.js';
import connectToDatabase from './database/mongodb.js';
import errorMiddleware from './middlewares/error.middleware.js';
import cookieParser from 'cookie-parser';
import arcjetMiddleware from './middlewares/arcjet.middleware.js';
import workflowRouter from './routes/workflow.routes.js';
const app = express();
app.set('trust proxy', true);
app.use(express.json());
app.use(express.urlencoded({extended:false}));
app.use(cookieParser());
app.use(arcjetMiddleware)
app.use('/api/v1/auth', authRouter);
app.use('/api/v1/users', userRouter);
app.use('/api/v1/subscriptions', subscriptionRouter);
app.use('/api/v1/workflows', workflowRouter);
// Health check endpoint
app.get('/health', (req, res) => {
res.status(200).json({
status: 'OK',
message: 'PayLoop API is running smoothly',
timestamp: new Date().toISOString(),
version: '1.0.0',
uptime: process.uptime()
});
});
app.use(errorMiddleware);
app.get('/', (req, res) => {
res.send(`
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PayLoop API - Smart Subscription Management</title>
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Ccircle cx='50' cy='50' r='45' fill='%234299e1'/%3E%3Cpath d='M30 35h40v30H30z' fill='white'/%3E%3Ccircle cx='50' cy='50' r='8' fill='%234299e1'/%3E%3Cpath d='M35 45l10 10 20-20' stroke='white' stroke-width='3' fill='none'/%3E%3C/svg%3E">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
line-height: 1.6;
color: #1a202c;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 2rem;
}
.hero {
text-align: center;
color: white;
margin-bottom: 3rem;
}
.hero h1 {
font-size: 3rem;
font-weight: 700;
margin-bottom: 1rem;
text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.hero p {
font-size: 1.2rem;
opacity: 0.9;
margin-bottom: 2rem;
}
.status {
display: inline-flex;
align-items: center;
background: rgba(255,255,255,0.2);
padding: 0.5rem 1rem;
border-radius: 50px;
backdrop-filter: blur(10px);
margin-bottom: 2rem;
}
.status-dot {
width: 8px;
height: 8px;
background: #48bb78;
border-radius: 50%;
margin-right: 0.5rem;
animation: pulse 2s infinite;
}
@keyframes pulse {
0% { transform: scale(1); opacity: 1; }
50% { transform: scale(1.1); opacity: 0.7; }
100% { transform: scale(1); opacity: 1; }
}
.api-docs {
background: white;
border-radius: 16px;
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
overflow: hidden;
}
.api-header {
background: linear-gradient(135deg, #4299e1 0%, #3182ce 100%);
color: white;
padding: 2rem;
}
.api-header h2 {
font-size: 1.8rem;
margin-bottom: 0.5rem;
}
.api-section {
padding: 2rem;
border-bottom: 1px solid #e2e8f0;
}
.api-section:last-child {
border-bottom: none;
}
.section-title {
font-size: 1.3rem;
font-weight: 600;
color: #2d3748;
margin-bottom: 1rem;
display: flex;
align-items: center;
}
.section-icon {
margin-right: 0.5rem;
font-size: 1.5rem;
}
.endpoint {
display: flex;
align-items: center;
padding: 1rem;
margin: 0.5rem 0;
background: #f7fafc;
border-radius: 8px;
border-left: 4px solid;
transition: all 0.2s ease;
}
.endpoint:hover {
transform: translateX(4px);
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.method {
font-weight: 700;
padding: 0.25rem 0.75rem;
border-radius: 4px;
font-size: 0.875rem;
margin-right: 1rem;
min-width: 60px;
text-align: center;
}
.method.post {
background: #48bb78;
color: white;
}
.method.get {
background: #4299e1;
color: white;
}
.method.put {
background: #ed8936;
color: white;
}
.method.delete {
background: #f56565;
color: white;
}
.endpoint.post { border-left-color: #48bb78; }
.endpoint.get { border-left-color: #4299e1; }
.endpoint.put { border-left-color: #ed8936; }
.endpoint.delete { border-left-color: #f56565; }
.endpoint-path {
font-family: 'Monaco', 'Menlo', monospace;
font-weight: 600;
color: #2d3748;
margin-right: auto;
}
.endpoint-desc {
color: #718096;
font-size: 0.875rem;
}
.base-url {
background: #2d3748;
color: white;
padding: 1rem;
border-radius: 8px;
font-family: 'Monaco', 'Menlo', monospace;
margin-bottom: 1rem;
text-align: center;
}
.footer {
text-align: center;
color: white;
margin-top: 3rem;
opacity: 0.8;
}
.footer a {
color: white;
text-decoration: none;
font-weight: 500;
}
.footer a:hover {
text-decoration: underline;
}
@media (max-width: 768px) {
.hero h1 {
font-size: 2rem;
}
.container {
padding: 1rem;
}
.endpoint {
flex-direction: column;
align-items: flex-start;
}
.method {
margin-bottom: 0.5rem;
}
}
</style>
</head>
<body>
<div class="container">
<div class="hero">
<h1>🔄 PayLoop API</h1>
<p>Smart Subscription Management & Automated Reminder System</p>
<div class="status">
<div class="status-dot"></div>
<span>API Status: Online</span>
</div>
</div>
<div class="api-docs">
<div class="api-header">
<h2>API Documentation</h2>
<p>RESTful API for managing subscriptions with automated workflows</p>
</div>
<div class="base-url">
<strong>Base URL:</strong> https://payloop-r4mr.onrender.com
</div>
<div class="api-section">
<div class="section-title">
<span class="section-icon">🔐</span>
Authentication
</div>
<div class="endpoint post">
<span class="method post">POST</span>
<span class="endpoint-path">/api/v1/auth/sign-up</span>
<span class="endpoint-desc">Register new user account</span>
</div>
<div class="endpoint post">
<span class="method post">POST</span>
<span class="endpoint-path">/api/v1/auth/sign-in</span>
<span class="endpoint-desc">User login & token generation</span>
</div>
<div class="endpoint post">
<span class="method post">POST</span>
<span class="endpoint-path">/api/v1/auth/sign-out</span>
<span class="endpoint-desc">User logout</span>
</div>
</div>
<div class="api-section">
<div class="section-title">
<span class="section-icon">📋</span>
Subscription Management
</div>
<div class="endpoint get">
<span class="method get">GET</span>
<span class="endpoint-path">/api/v1/subscriptions</span>
<span class="endpoint-desc">Get all subscriptions</span>
</div>
<div class="endpoint get">
<span class="method get">GET</span>
<span class="endpoint-path">/api/v1/subscriptions/:id</span>
<span class="endpoint-desc">Get subscription details</span>
</div>
<div class="endpoint post">
<span class="method post">POST</span>
<span class="endpoint-path">/api/v1/subscriptions</span>
<span class="endpoint-desc">Create new subscription</span>
</div>
<div class="endpoint get">
<span class="method get">GET</span>
<span class="endpoint-path">/api/v1/subscriptions/user/:id</span>
<span class="endpoint-desc">Get user subscriptions</span>
</div>
<div class="endpoint put">
<span class="method put">PUT</span>
<span class="endpoint-path">/api/v1/subscriptions/:id</span>
<span class="endpoint-desc">Update subscription</span>
</div>
<div class="endpoint put">
<span class="method put">PUT</span>
<span class="endpoint-path">/api/v1/subscriptions/:id/cancel</span>
<span class="endpoint-desc">Cancel subscription</span>
</div>
<div class="endpoint delete">
<span class="method delete">DELETE</span>
<span class="endpoint-path">/api/v1/subscriptions/:id</span>
<span class="endpoint-desc">Delete subscription</span>
</div>
<div class="endpoint get">
<span class="method get">GET</span>
<span class="endpoint-path">/api/v1/subscriptions/upcoming-renewals</span>
<span class="endpoint-desc">Get upcoming renewals</span>
</div>
</div>
<div class="api-section">
<div class="section-title">
<span class="section-icon">👥</span>
User Management
</div>
<div class="endpoint get">
<span class="method get">GET</span>
<span class="endpoint-path">/api/v1/users</span>
<span class="endpoint-desc">Get all users</span>
</div>
<div class="endpoint get">
<span class="method get">GET</span>
<span class="endpoint-path">/api/v1/users/:id</span>
<span class="endpoint-desc">Get user by ID</span>
</div>
<div class="endpoint post">
<span class="method post">POST</span>
<span class="endpoint-path">/api/v1/users</span>
<span class="endpoint-desc">Create new user</span>
</div>
<div class="endpoint put">
<span class="method put">PUT</span>
<span class="endpoint-path">/api/v1/users/:id</span>
<span class="endpoint-desc">Update user</span>
</div>
<div class="endpoint delete">
<span class="method delete">DELETE</span>
<span class="endpoint-path">/api/v1/users/:id</span>
<span class="endpoint-desc">Delete user</span>
</div>
</div>
<div class="api-section">
<div class="section-title">
<span class="section-icon">🔄</span>
Workflow System
</div>
<div class="endpoint post">
<span class="method post">POST</span>
<span class="endpoint-path">/api/v1/workflows/subscription/reminder</span>
<span class="endpoint-desc">Automated reminder workflows</span>
</div>
</div>
<div class="api-section">
<div class="section-title">
<span class="section-icon">🏥</span>
System Health
</div>
<div class="endpoint get">
<span class="method get">GET</span>
<span class="endpoint-path">/health</span>
<span class="endpoint-desc">API health check</span>
</div>
</div>
</div>
<div class="footer">
<p>Built with ❤️ by <a href="https://mohdyaser.vercel.app/" target="_blank">Mohamed Yaser</a></p>
<p>📧 <a href="mailto:1ammar.yaser@gmail.com">1ammar.yaser@gmail.com</a> |
🐙 <a href="https://github.com/Yaser-123/PayLoop" target="_blank">GitHub</a> |
💼 <a href="https://www.linkedin.com/in/mohamedyaser08/" target="_blank">LinkedIn</a></p>
</div>
</div>
</body>
</html>
`);
})
app.listen(PORT,async () => {
console.log(`Subscription tracking app API is running on http://localhost:${PORT}`);
await connectToDatabase();
})
export default app;