@fydemy/cms 1.0.1 → 1.0.3

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/README.md CHANGED
@@ -32,24 +32,29 @@ yarn add @fydemy/cms
32
32
 
33
33
  ### 1. Initialize the CMS
34
34
 
35
- Create a script to initialize your content directory:
35
+ Run the initialization command in your Next.js App Router project:
36
36
 
37
- ```typescript
38
- // scripts/init-cms.ts
39
- import { initCMS } from "@fydemy/cms";
40
-
41
- initCMS();
37
+ ```bash
38
+ npx fydemy-cms init
42
39
  ```
43
40
 
44
- Run it:
41
+ This command will automatically:
42
+
43
+ - Create the content directory
44
+ - Scaffold Admin UI pages (`/app/admin`)
45
+ - Create API routes (`/app/api/cms`)
46
+ - Create a `.env.local.example` file
47
+ - Provide instructions for updating `middleware.ts`
48
+
49
+ ### 2. Configure Environment
50
+
51
+ Copy `.env.local.example` to `.env.local` and set your credentials:
45
52
 
46
53
  ```bash
47
- npx tsx scripts/init-cms.ts
54
+ cp .env.local.example .env.local
48
55
  ```
49
56
 
50
- ### 2. Set Environment Variables
51
-
52
- Create `.env.local`:
57
+ Update variables in `.env.local`:
53
58
 
54
59
  ```env
55
60
  # Required for authentication
@@ -65,62 +70,24 @@ GITHUB_BRANCH=main
65
70
 
66
71
  > **Security Note**: Use strong passwords and keep `CMS_SESSION_SECRET` at least 32 characters long.
67
72
 
68
- ### 3. Set Up API Routes
69
-
70
- Create the following API routes in your Next.js app:
71
-
72
- **`app/api/cms/login/route.ts`**
73
-
74
- ```typescript
75
- import { handleLogin } from "@fydemy/cms";
76
- export { handleLogin as POST };
77
- ```
78
-
79
- **`app/api/cms/logout/route.ts`**
80
-
81
- ```typescript
82
- import { handleLogout } from "@fydemy/cms";
83
- export { handleLogout as POST };
84
- ```
85
-
86
- **`app/api/cms/content/[...path]/route.ts`**
87
-
88
- ```typescript
89
- import { createContentApiHandlers } from "@fydemy/cms";
90
-
91
- const handlers = createContentApiHandlers();
92
- export const GET = handlers.GET;
93
- export const POST = handlers.POST;
94
- export const DELETE = handlers.DELETE;
95
- ```
73
+ ### 3. Update Middleware
96
74
 
97
- **`app/api/cms/list/[[...path]]/route.ts`**
98
-
99
- ```typescript
100
- import { createListApiHandlers } from "@fydemy/cms";
101
-
102
- const handlers = createListApiHandlers();
103
- export const GET = handlers.GET;
104
- ```
105
-
106
- ### 4. Add Middleware
107
-
108
- **`middleware.ts`** (root of your project)
75
+ The init command will guide you to update `middleware.ts` to protect admin routes:
109
76
 
110
77
  ```typescript
111
78
  import { createAuthMiddleware } from "@fydemy/cms";
79
+ import { NextRequest } from "next/server";
112
80
 
113
- export const middleware = createAuthMiddleware({
114
- loginPath: "/admin/login",
115
- protectedPaths: ["/admin"],
116
- });
81
+ export function middleware(request: NextRequest) {
82
+ return createAuthMiddleware()(request);
83
+ }
117
84
 
118
85
  export const config = {
119
86
  matcher: ["/admin/:path*"],
120
87
  };
121
88
  ```
122
89
 
123
- ### 5. Read Content in Your App
90
+ ### 4. Read Content in Your App
124
91
 
125
92
  ```typescript
126
93
  import { getMarkdownContent } from "@fydemy/cms";