@@ -135,18 +135,41 @@ const MOCK_ENTRIES: ChangelogEntry[] = [
135135 } ,
136136] ;
137137
138+ // In-memory store for development
139+ const devStore : ChangelogEntry [ ] = [ ] ;
140+
138141export async function saveEntry ( entry : ChangelogEntry ) {
142+ if ( process . env . NODE_ENV === "development" ) {
143+ console . log ( "Development mode: saving to in-memory store" ) ;
144+ // Add to start of array to match the sorting in getAllEntries
145+ devStore . unshift ( entry ) ;
146+ return ;
147+ }
148+
139149 try {
140150 const store = getStore ( "changelog-store" ) ;
141151 await store . setJSON ( entry . id . toString ( ) , entry ) ;
152+
153+ // Trigger revalidation
154+ const baseUrl = process . env . NEXT_PUBLIC_BASE_URL || "http://localhost:3000" ;
155+ await fetch ( `${ baseUrl } /api/revalidate` , {
156+ method : "POST" ,
157+ headers : {
158+ Authorization : `Bearer ${ process . env . REVALIDATION_TOKEN } ` ,
159+ } ,
160+ } ) ;
142161 } catch ( error ) {
143162 console . warn ( "Failed to save entry:" , error ) ;
144- // In development/build, just log the entry
145163 console . log ( "Would have saved:" , entry ) ;
146164 }
147165}
148166
149167export async function getAllEntries ( ) : Promise < ChangelogEntry [ ] > {
168+ if ( process . env . NODE_ENV === "development" ) {
169+ console . log ( "Development mode: reading from in-memory store" ) ;
170+ return devStore . length > 0 ? devStore : MOCK_ENTRIES ;
171+ }
172+
150173 try {
151174 const store = getStore ( "changelog-store" ) ;
152175 const list = await store . list ( ) ;
@@ -164,7 +187,6 @@ export async function getAllEntries(): Promise<ChangelogEntry[]> {
164187 ) ;
165188 } catch ( error ) {
166189 console . warn ( "Failed to get entries:" , error ) ;
167- // Return mock data in development/build
168190 return MOCK_ENTRIES ;
169191 }
170192}
0 commit comments