kapi-mvc-blank 1.0.0

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.
@@ -0,0 +1,47 @@
1
+ <?php
2
+ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['image'])) {
3
+ $file = $_FILES['image'];
4
+ $filename = basename($file['name']);
5
+
6
+ $url = 'http://localhost:3000/api/v1/uploads/' . $filename;
7
+
8
+ $ch = curl_init();
9
+ curl_setopt($ch, CURLOPT_URL, $url);
10
+ curl_setopt($ch, CURLOPT_POST, 1);
11
+ curl_setopt($ch, CURLOPT_POSTFIELDS, [
12
+ 'image' => new CURLFile($file['tmp_name'], $file['type'], $filename)
13
+ ]);
14
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
15
+ $response = curl_exec($ch);
16
+ echo $response ? "Image uploaded successfully" : "Image upload failed";
17
+ } else {
18
+ echo "No image uploaded";
19
+ }
20
+ ?>
21
+ <form id="uploadForm">
22
+ <input type="file" id="imageInput" name="image" required>
23
+ <button type="submit">Upload</button>
24
+ </form>
25
+ <hr>
26
+ <h2>Test PHP cURL POST</h2>
27
+ <form method="POST" enctype="multipart/form-data">
28
+ <input type="file" name="image" required>
29
+ <button type="submit">Upload via PHP</button>
30
+ </form>
31
+ <script>
32
+ document.getElementById('uploadForm').addEventListener('submit', function(e) {
33
+ e.preventDefault();
34
+
35
+ const file = document.getElementById('imageInput').files[0];
36
+ const formData = new FormData();
37
+ formData.append('image', file);
38
+
39
+ fetch('http://localhost:3000/api/v1/uploads/' + file.name, {
40
+ method: 'POST',
41
+ body: formData
42
+ })
43
+ .then(response => response.text())
44
+ .then(data => console.log(data))
45
+ .catch(error => console.error('Error:', error));
46
+ });
47
+ </script>
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env node
2
+ import http from 'http';
3
+
4
+ function testEndpoint(path, method = 'GET') {
5
+ return new Promise((resolve) => {
6
+ const options = {
7
+ hostname: 'localhost',
8
+ port: 3000,
9
+ path,
10
+ method
11
+ };
12
+
13
+ const req = http.request(options, (res) => {
14
+ let data = '';
15
+
16
+ res.on('data', (chunk) => {
17
+ data += chunk;
18
+ });
19
+
20
+ res.on('end', () => {
21
+ try {
22
+ const parsed = JSON.parse(data);
23
+ resolve({ status: res.statusCode, data: parsed });
24
+ } catch {
25
+ resolve({ status: res.statusCode, data });
26
+ }
27
+ });
28
+ });
29
+
30
+ req.on('error', (error) => {
31
+ resolve({ error: error.message });
32
+ });
33
+
34
+ req.end();
35
+ });
36
+ }
37
+
38
+ console.log('๐Ÿงช Testing API endpoints...\n');
39
+
40
+ // Test v1
41
+ const v1Info = await testEndpoint('/api/v1/users/info');
42
+ console.log('โœ“ GET /api/v1/users/info');
43
+ console.log(' Response:', JSON.stringify(v1Info.data, null, 2));
44
+
45
+ // Test v2
46
+ const v2Info = await testEndpoint('/api/v2/users/info');
47
+ console.log('\nโœ“ GET /api/v2/users/info');
48
+ console.log(' Response:', JSON.stringify(v2Info.data, null, 2));
49
+
50
+ console.log('\nโœ… Tests completed!');
51
+ process.exit(0);
package/test-setup.js ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env node
2
+ import app, { initializeRoutes } from './src/app.js';
3
+
4
+ const PORT = process.env.PORT || 3000;
5
+
6
+ console.log('๐Ÿ”„ Initializing routes...');
7
+ await initializeRoutes();
8
+
9
+ console.log('โœ… Routes initialized successfully!');
10
+ console.log('\nRegistered API endpoints:');
11
+ console.log(' - GET /api/v1/users/info');
12
+ console.log(' - GET /api/v1/users/profile (requires auth)');
13
+ console.log(' - POST /api/v1/auth/register');
14
+ console.log(' - POST /api/v1/auth/login');
15
+ console.log(' - POST /api/v1/uploads/:name');
16
+ console.log(' - GET /docs (Swagger UI)');
17
+ console.log(' - GET /docs.json (OpenAPI spec)');
18
+
19
+ app.listen(PORT, () => {
20
+ console.log(`\n๐Ÿš€ Server running on port ${PORT}`);
21
+ });