create-nara 1.0.26 → 1.0.27

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.

Potentially problematic release.


This version of create-nara might be problematic. Click here for more details.

package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-nara",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "CLI to scaffold NARA projects",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,26 +1,30 @@
1
1
  import { ValidationError, jsonValidationError, jsonError } from '@nara-web/core';
2
- import type { NaraRequest, NaraResponse, NaraHandler } from '@nara-web/core';
2
+ import type { NaraRequest, NaraResponse } from '@nara-web/core';
3
+
4
+ type AsyncHandler = (req: NaraRequest, res: NaraResponse) => Promise<any> | any;
3
5
 
4
6
  /**
5
7
  * Wraps a route handler with error handling
6
8
  */
7
- export function wrapHandler(handler: NaraHandler): NaraHandler {
9
+ export function wrapHandler(handler: AsyncHandler): any {
8
10
  return async (req: NaraRequest, res: NaraResponse) => {
9
11
  try {
10
12
  await handler(req, res);
11
13
  } catch (error: any) {
12
14
  if (error instanceof ValidationError) {
13
- return jsonValidationError(res, error.errors);
15
+ jsonValidationError(res, error.errors);
16
+ return;
14
17
  }
15
18
 
16
19
  // Handle other HttpErrors
17
20
  if (error.statusCode) {
18
- return jsonError(res, error.message, error.statusCode);
21
+ jsonError(res, error.message, error.statusCode);
22
+ return;
19
23
  }
20
24
 
21
25
  // Unknown error
22
26
  console.error('[Unhandled Error]:', error);
23
- return jsonError(res, 'Internal server error', 500);
27
+ jsonError(res, 'Internal server error', 500);
24
28
  }
25
29
  };
26
30
  }
@@ -1,10 +1,12 @@
1
1
  import { ValidationError, jsonValidationError, jsonError } from '@nara-web/core';
2
- import type { NaraRequest, NaraResponse, NaraHandler } from '@nara-web/core';
2
+ import type { NaraRequest, NaraResponse } from '@nara-web/core';
3
+
4
+ type AsyncHandler = (req: NaraRequest, res: NaraResponse) => Promise<any> | any;
3
5
 
4
6
  /**
5
7
  * Wraps a route handler with error handling
6
8
  */
7
- export function wrapHandler(handler: NaraHandler): NaraHandler {
9
+ export function wrapHandler(handler: AsyncHandler): any {
8
10
  return async (req: NaraRequest, res: NaraResponse) => {
9
11
  try {
10
12
  await handler(req, res);
@@ -16,34 +16,32 @@ export function registerRoutes(app: NaraApp) {
16
16
 
17
17
  // Public
18
18
  app.get('/', (req, res) => {
19
- return res.inertia('landing', {
20
- title: 'Welcome to NARA'
21
- });
19
+ res.inertia('landing', { title: 'Welcome to NARA' });
22
20
  });
23
21
 
24
22
  // Guest only
25
23
  app.get('/login', guestMiddleware as any, (req, res) => {
26
- return res.inertia('auth/login');
24
+ res.inertia('auth/login');
27
25
  });
28
26
  app.get('/register', guestMiddleware as any, (req, res) => {
29
- return res.inertia('auth/register');
27
+ res.inertia('auth/register');
30
28
  });
31
29
  app.get('/forgot-password', guestMiddleware as any, (req, res) => {
32
- return res.inertia('auth/forgot-password');
30
+ res.inertia('auth/forgot-password');
33
31
  });
34
32
  app.get('/reset-password/:token', guestMiddleware as any, (req, res) => {
35
- return res.inertia('auth/reset-password', { token: req.params.token });
33
+ res.inertia('auth/reset-password', { token: req.params.token });
36
34
  });
37
35
 
38
36
  // Protected
39
37
  app.get('/dashboard', webAuthMiddleware as any, (req, res) => {
40
- return res.inertia('dashboard');
38
+ res.inertia('dashboard');
41
39
  });
42
40
  app.get('/users', webAuthMiddleware as any, (req, res) => {
43
- return res.inertia('users');
41
+ res.inertia('users');
44
42
  });
45
43
  app.get('/profile', webAuthMiddleware as any, (req, res) => {
46
- return res.inertia('profile');
44
+ res.inertia('profile');
47
45
  });
48
46
 
49
47
 
@@ -71,4 +69,10 @@ export function registerRoutes(app: NaraApp) {
71
69
  // Uploads
72
70
  app.post('/api/uploads', wrapHandler((req, res) => upload.upload(req, res)));
73
71
  app.delete('/api/uploads/:filename', wrapHandler((req, res) => upload.delete(req, res)));
72
+
73
+ // Static files
74
+ app.get('/uploads/*', (req, res) => {
75
+ const filePath = req.path.replace('/uploads/', '');
76
+ res.sendFile(`uploads/${filePath}`);
77
+ });
74
78
  }
@@ -1,26 +1,30 @@
1
1
  import { ValidationError, jsonValidationError, jsonError } from '@nara-web/core';
2
- import type { NaraRequest, NaraResponse, NaraHandler } from '@nara-web/core';
2
+ import type { NaraRequest, NaraResponse } from '@nara-web/core';
3
+
4
+ type AsyncHandler = (req: NaraRequest, res: NaraResponse) => Promise<any> | any;
3
5
 
4
6
  /**
5
7
  * Wraps a route handler with error handling
6
8
  */
7
- export function wrapHandler(handler: NaraHandler): NaraHandler {
9
+ export function wrapHandler(handler: AsyncHandler): any {
8
10
  return async (req: NaraRequest, res: NaraResponse) => {
9
11
  try {
10
12
  await handler(req, res);
11
13
  } catch (error: any) {
12
14
  if (error instanceof ValidationError) {
13
- return jsonValidationError(res, error.errors);
15
+ jsonValidationError(res, error.errors);
16
+ return;
14
17
  }
15
18
 
16
19
  // Handle other HttpErrors
17
20
  if (error.statusCode) {
18
- return jsonError(res, error.message, error.statusCode);
21
+ jsonError(res, error.message, error.statusCode);
22
+ return;
19
23
  }
20
24
 
21
25
  // Unknown error
22
26
  console.error('[Unhandled Error]:', error);
23
- return jsonError(res, 'Internal server error', 500);
27
+ jsonError(res, 'Internal server error', 500);
24
28
  }
25
29
  };
26
30
  }
@@ -16,34 +16,32 @@ export function registerRoutes(app: NaraApp) {
16
16
 
17
17
  // Public
18
18
  app.get('/', (req, res) => {
19
- return res.inertia('landing', {
20
- title: 'Welcome to NARA'
21
- });
19
+ res.inertia('landing', { title: 'Welcome to NARA' });
22
20
  });
23
21
 
24
22
  // Guest only
25
23
  app.get('/login', guestMiddleware as any, (req, res) => {
26
- return res.inertia('auth/login');
24
+ res.inertia('auth/login');
27
25
  });
28
26
  app.get('/register', guestMiddleware as any, (req, res) => {
29
- return res.inertia('auth/register');
27
+ res.inertia('auth/register');
30
28
  });
31
29
  app.get('/forgot-password', guestMiddleware as any, (req, res) => {
32
- return res.inertia('auth/forgot-password');
30
+ res.inertia('auth/forgot-password');
33
31
  });
34
32
  app.get('/reset-password/:token', guestMiddleware as any, (req, res) => {
35
- return res.inertia('auth/reset-password', { token: req.params.token });
33
+ res.inertia('auth/reset-password', { token: req.params.token });
36
34
  });
37
35
 
38
36
  // Protected
39
37
  app.get('/dashboard', webAuthMiddleware as any, (req, res) => {
40
- return res.inertia('dashboard');
38
+ res.inertia('dashboard');
41
39
  });
42
40
  app.get('/users', webAuthMiddleware as any, (req, res) => {
43
- return res.inertia('users');
41
+ res.inertia('users');
44
42
  });
45
43
  app.get('/profile', webAuthMiddleware as any, (req, res) => {
46
- return res.inertia('profile');
44
+ res.inertia('profile');
47
45
  });
48
46
 
49
47
 
@@ -71,4 +69,10 @@ export function registerRoutes(app: NaraApp) {
71
69
  // Uploads
72
70
  app.post('/api/uploads', wrapHandler((req, res) => upload.upload(req, res)));
73
71
  app.delete('/api/uploads/:filename', wrapHandler((req, res) => upload.delete(req, res)));
72
+
73
+ // Static files
74
+ app.get('/uploads/*', (req, res) => {
75
+ const filePath = req.path.replace('/uploads/', '');
76
+ res.sendFile(`uploads/${filePath}`);
77
+ });
74
78
  }