baraqex 1.0.67 ā 1.0.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +17 -3
- package/dist/index.js.map +2 -2
- package/dist/server/api-router.d.ts +3 -1
- package/dist/server/api-router.d.ts.map +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +17 -3
- package/dist/server/index.js.map +2 -2
- package/package.json +1 -1
- package/templates/fullstack-template/.env.example +16 -29
- package/templates/fullstack-template/README.md +9 -45
- package/templates/fullstack-template/package-lock.json +1504 -6211
- package/templates/fullstack-template/package.json +16 -46
- package/templates/fullstack-template/server.js +52 -25
- package/templates/fullstack-template/src/App.tsx +178 -1
- package/templates/fullstack-template/src/api/hello.js +19 -0
- package/templates/fullstack-template/src/api/users.js +39 -0
- package/templates/fullstack-template/src/pages/index.tsx +200 -0
- package/templates/fullstack-template/src/server.ts +162 -98
- package/templates/fullstack-template/tsconfig.json +30 -0
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import { createServer, AuthService, Database } from 'baraqex/server';
|
|
2
|
-
import helmet from 'helmet';
|
|
3
|
-
import compression from 'compression';
|
|
4
|
-
import rateLimit from 'express-rate-limit';
|
|
5
|
-
import morgan from 'morgan';
|
|
6
1
|
import dotenv from 'dotenv';
|
|
7
2
|
|
|
8
3
|
// Load environment variables
|
|
@@ -31,70 +26,170 @@ const config = {
|
|
|
31
26
|
}
|
|
32
27
|
};
|
|
33
28
|
|
|
34
|
-
//
|
|
35
|
-
|
|
29
|
+
// Wait for baraqex to be ready
|
|
30
|
+
async function waitForBaraqex() {
|
|
31
|
+
const maxWait = 10000;
|
|
32
|
+
const interval = 100;
|
|
33
|
+
let waited = 0;
|
|
34
|
+
|
|
35
|
+
while (waited < maxWait) {
|
|
36
|
+
try {
|
|
37
|
+
const baraqex = await import('baraqex');
|
|
38
|
+
if (baraqex.createServer && typeof baraqex.createServer === 'function') {
|
|
39
|
+
return baraqex;
|
|
40
|
+
}
|
|
41
|
+
} catch (error) {
|
|
42
|
+
// Continue waiting
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
await new Promise(resolve => setTimeout(resolve, interval));
|
|
46
|
+
waited += interval;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
throw new Error('Baraqex failed to initialize within timeout period');
|
|
50
|
+
}
|
|
36
51
|
|
|
37
|
-
//
|
|
38
|
-
|
|
52
|
+
// Async function to start server
|
|
53
|
+
async function startServer() {
|
|
54
|
+
try {
|
|
55
|
+
console.log('š Waiting for Baraqex to initialize...');
|
|
56
|
+
|
|
57
|
+
// Wait for baraqex to be ready
|
|
58
|
+
const baraqex = await waitForBaraqex();
|
|
59
|
+
const { createServer } = baraqex;
|
|
60
|
+
|
|
61
|
+
console.log('ā
Baraqex initialized successfully');
|
|
62
|
+
|
|
63
|
+
if (!createServer || typeof createServer !== 'function') {
|
|
64
|
+
throw new Error('createServer function not available from baraqex package');
|
|
65
|
+
}
|
|
39
66
|
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
styleSrc: ["'self'", "'unsafe-inline'"],
|
|
46
|
-
scriptSrc: ["'self'"],
|
|
47
|
-
imgSrc: ["'self'", "data:", "https:"],
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
}));
|
|
67
|
+
// Create server instance
|
|
68
|
+
const server = createServer(config);
|
|
69
|
+
|
|
70
|
+
// Wait for server initialization
|
|
71
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
51
72
|
|
|
52
|
-
//
|
|
53
|
-
|
|
73
|
+
// Start the server first
|
|
74
|
+
console.log('š Starting server...');
|
|
75
|
+
await server.start();
|
|
76
|
+
|
|
77
|
+
// Then try to set up additional endpoints after server is running
|
|
78
|
+
try {
|
|
79
|
+
if (typeof server.getExpressApp === 'function') {
|
|
80
|
+
const app = server.getExpressApp();
|
|
81
|
+
|
|
82
|
+
if (app) {
|
|
83
|
+
// Health check endpoint
|
|
84
|
+
app.get('/health', (req, res) => {
|
|
85
|
+
res.json({
|
|
86
|
+
status: 'ok',
|
|
87
|
+
timestamp: new Date().toISOString(),
|
|
88
|
+
version: process.env.npm_package_version || '1.0.0',
|
|
89
|
+
environment: process.env.NODE_ENV || 'development'
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// API status endpoint
|
|
94
|
+
app.get('/api/status', (req, res) => {
|
|
95
|
+
let db = null;
|
|
96
|
+
let auth = null;
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
if (typeof server.getDatabase === 'function') {
|
|
100
|
+
db = server.getDatabase();
|
|
101
|
+
}
|
|
102
|
+
} catch (e) {
|
|
103
|
+
// Database method not available
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
if (typeof server.getAuth === 'function') {
|
|
108
|
+
auth = server.getAuth();
|
|
109
|
+
}
|
|
110
|
+
} catch (e) {
|
|
111
|
+
// Auth method not available
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
res.json({
|
|
115
|
+
api: 'online',
|
|
116
|
+
database: db ? 'connected' : 'not configured',
|
|
117
|
+
authentication: auth ? 'enabled' : 'disabled',
|
|
118
|
+
timestamp: new Date().toISOString()
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
} catch (setupError) {
|
|
124
|
+
console.warn('ā ļø Could not set up additional endpoints:', setupError.message);
|
|
125
|
+
}
|
|
54
126
|
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
127
|
+
// Database connection (if configured)
|
|
128
|
+
await connectDatabase(server);
|
|
129
|
+
|
|
130
|
+
console.log(`š Fullstack server running on http://localhost:${config.port}`);
|
|
131
|
+
console.log(`š Environment: ${process.env.NODE_ENV || 'development'}`);
|
|
132
|
+
|
|
133
|
+
// Safely check auth status
|
|
134
|
+
let authStatus = 'disabled';
|
|
135
|
+
try {
|
|
136
|
+
if (typeof server.getAuth === 'function') {
|
|
137
|
+
authStatus = server.getAuth() ? 'enabled' : 'disabled';
|
|
138
|
+
}
|
|
139
|
+
} catch (e) {
|
|
140
|
+
// Auth check failed
|
|
141
|
+
}
|
|
142
|
+
console.log(`š Auth: ${authStatus}`);
|
|
143
|
+
|
|
144
|
+
// Safely check database status
|
|
145
|
+
let dbStatus = 'not configured';
|
|
146
|
+
try {
|
|
147
|
+
if (typeof server.getDatabase === 'function') {
|
|
148
|
+
dbStatus = server.getDatabase() ? 'connected' : 'not configured';
|
|
149
|
+
}
|
|
150
|
+
} catch (e) {
|
|
151
|
+
// Database check failed
|
|
152
|
+
}
|
|
153
|
+
console.log(`š¾ Database: ${dbStatus}`);
|
|
154
|
+
|
|
155
|
+
console.log(`š API docs: http://localhost:${config.port}/api-docs`);
|
|
156
|
+
console.log(`ā¤ļø Health check: http://localhost:${config.port}/health`);
|
|
157
|
+
|
|
158
|
+
return server;
|
|
159
|
+
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.error('ā Failed to start server:', error);
|
|
162
|
+
|
|
163
|
+
if (error.message.includes('Express not installed')) {
|
|
164
|
+
console.log('\nš” To fix this, run:');
|
|
165
|
+
console.log(' npm install express @types/express');
|
|
166
|
+
} else if (error.message.includes('createServer function not available')) {
|
|
167
|
+
console.log('\nš” To fix this, make sure baraqex is properly installed:');
|
|
168
|
+
console.log(' npm install baraqex');
|
|
169
|
+
console.log(' npm install express @types/express');
|
|
170
|
+
} else if (error.message.includes('timeout')) {
|
|
171
|
+
console.log('\nš” Baraqex is taking longer than expected to initialize.');
|
|
172
|
+
console.log(' This might be due to missing dependencies.');
|
|
173
|
+
console.log(' Try installing: npm install express @types/express');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
process.exit(1);
|
|
177
|
+
}
|
|
58
178
|
}
|
|
59
179
|
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
180
|
+
// Database connection helper
|
|
181
|
+
async function connectDatabase(server) {
|
|
182
|
+
let db = null;
|
|
183
|
+
try {
|
|
184
|
+
if (typeof server.getDatabase === 'function') {
|
|
185
|
+
db = server.getDatabase();
|
|
186
|
+
}
|
|
187
|
+
} catch (e) {
|
|
188
|
+
console.log('ā ļø Database functionality not available');
|
|
189
|
+
return;
|
|
66
190
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// Health check endpoint
|
|
71
|
-
app.get('/health', (req, res) => {
|
|
72
|
-
res.json({
|
|
73
|
-
status: 'ok',
|
|
74
|
-
timestamp: new Date().toISOString(),
|
|
75
|
-
version: process.env.npm_package_version || '1.0.0',
|
|
76
|
-
environment: process.env.NODE_ENV || 'development'
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
// API status endpoint
|
|
81
|
-
app.get('/api/status', (req, res) => {
|
|
82
|
-
const db = server.getDatabase();
|
|
83
|
-
res.json({
|
|
84
|
-
api: 'online',
|
|
85
|
-
database: db ? 'connected' : 'not configured',
|
|
86
|
-
authentication: server.getAuth() ? 'enabled' : 'disabled',
|
|
87
|
-
timestamp: new Date().toISOString()
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// Enable SSR with hydration
|
|
92
|
-
server.enableSSR({ hydratable: true });
|
|
93
|
-
|
|
94
|
-
// Database connection
|
|
95
|
-
async function connectDatabase() {
|
|
96
|
-
const db = server.getDatabase();
|
|
97
|
-
if (db) {
|
|
191
|
+
|
|
192
|
+
if (db && typeof db.connect === 'function') {
|
|
98
193
|
try {
|
|
99
194
|
await db.connect();
|
|
100
195
|
console.log('ā
Database connected successfully');
|
|
@@ -112,42 +207,13 @@ async function connectDatabase() {
|
|
|
112
207
|
// Graceful shutdown
|
|
113
208
|
process.on('SIGTERM', async () => {
|
|
114
209
|
console.log('š SIGTERM received, shutting down gracefully...');
|
|
115
|
-
|
|
116
|
-
try {
|
|
117
|
-
await server.stop();
|
|
118
|
-
const db = server.getDatabase();
|
|
119
|
-
if (db) {
|
|
120
|
-
await db.disconnect();
|
|
121
|
-
}
|
|
122
|
-
console.log('ā
Server shut down complete');
|
|
123
|
-
process.exit(0);
|
|
124
|
-
} catch (error) {
|
|
125
|
-
console.error('ā Error during shutdown:', error);
|
|
126
|
-
process.exit(1);
|
|
127
|
-
}
|
|
210
|
+
process.exit(0);
|
|
128
211
|
});
|
|
129
212
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
await connectDatabase();
|
|
135
|
-
|
|
136
|
-
// Start the server
|
|
137
|
-
await server.start();
|
|
138
|
-
|
|
139
|
-
console.log(`š Fullstack server running on http://localhost:${config.port}`);
|
|
140
|
-
console.log(`š Environment: ${process.env.NODE_ENV || 'development'}`);
|
|
141
|
-
console.log(`š Auth: ${server.getAuth() ? 'enabled' : 'disabled'}`);
|
|
142
|
-
console.log(`š¾ Database: ${server.getDatabase() ? 'connected' : 'not configured'}`);
|
|
143
|
-
console.log(`š API docs: http://localhost:${config.port}/api-docs`);
|
|
144
|
-
console.log(`ā¤ļø Health check: http://localhost:${config.port}/health`);
|
|
145
|
-
|
|
146
|
-
} catch (error) {
|
|
147
|
-
console.error('ā Failed to start server:', error);
|
|
148
|
-
process.exit(1);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
213
|
+
process.on('SIGINT', async () => {
|
|
214
|
+
console.log('š SIGINT received, shutting down gracefully...');
|
|
215
|
+
process.exit(0);
|
|
216
|
+
});
|
|
151
217
|
|
|
152
218
|
// Handle unhandled promise rejections
|
|
153
219
|
process.on('unhandledRejection', (reason, promise) => {
|
|
@@ -163,5 +229,3 @@ process.on('uncaughtException', (error) => {
|
|
|
163
229
|
|
|
164
230
|
// Start the server
|
|
165
231
|
startServer();
|
|
166
|
-
|
|
167
|
-
export default server;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"allowSyntheticDefaultImports": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"allowJs": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"strict": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"outDir": "./dist",
|
|
14
|
+
"rootDir": "./src",
|
|
15
|
+
"resolveJsonModule": true,
|
|
16
|
+
"isolatedModules": true,
|
|
17
|
+
"noEmit": false,
|
|
18
|
+
"jsx": "react-jsx",
|
|
19
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"]
|
|
20
|
+
},
|
|
21
|
+
"include": [
|
|
22
|
+
"src/**/*"
|
|
23
|
+
],
|
|
24
|
+
"exclude": [
|
|
25
|
+
"node_modules",
|
|
26
|
+
"dist",
|
|
27
|
+
"**/*.test.ts",
|
|
28
|
+
"**/*.spec.ts"
|
|
29
|
+
]
|
|
30
|
+
}
|