@@ -19,6 +19,9 @@ const { NotificationService } = require('./src/services/notificationService');
1919const { SorobanLeaseService } = require ( './src/services/sorobanLeaseService' ) ;
2020const { LeaseRenewalService } = require ( './src/services/leaseRenewalService' ) ;
2121const { LeaseRenewalJob, startLeaseRenewalScheduler } = require ( './src/jobs/leaseRenewalJob' ) ;
22+ const { RentPaymentTrackerService } = require ( './services/rentPaymentTrackerService' ) ;
23+ const { startPaymentTrackerJob } = require ( './src/jobs/paymentTrackerJob' ) ;
24+ const { createPaymentRoutes } = require ( './src/routes/paymentRoutes' ) ;
2225const { getUSDCToFiatRates, getXLMToUSDCPath } = require ( './services/priceFeedService' ) ;
2326const AvailabilityService = require ( './services/availabilityService' ) ;
2427const AssetMetadataService = require ( './services/assetMetadataService' ) ;
@@ -80,6 +83,65 @@ function createApp(dependencies = {}) {
8083
8184 // Middleware
8285 app . use ( cors ( ) ) ;
86+ app . use ( express . json ( ) ) ;
87+ const express = require ( 'express' ) ;
88+ const cors = require ( 'cors' ) ;
89+ const { randomUUID } = require ( 'crypto' ) ;
90+
91+ const multer = require ( 'multer' ) ;
92+ const path = require ( 'path' ) ;
93+ const fs = require ( 'fs' ) ;
94+ const sharp = require ( 'sharp' ) ;
95+ const app = express ( ) ;
96+ const port = 3000 ;
97+ const creditScoreAggregator = new TenantCreditScoreAggregator ( ) ;
98+ const listings = [ ] ;
99+ const HORIZON_URL = process . env . HORIZON_URL || 'https://horizon.stellar.org' ;
100+
101+ const uploadDir = path . join ( __dirname , 'uploads' ) ;
102+ if ( ! fs . existsSync ( uploadDir ) ) {
103+ fs . mkdirSync ( uploadDir , { recursive : true } ) ;
104+ }
105+
106+ const storage = multer . diskStorage ( {
107+ destination : ( req , file , cb ) => cb ( null , uploadDir ) ,
108+ filename : ( req , file , cb ) => cb ( null , `${ Date . now ( ) } _${ file . originalname } ` )
109+ } ) ;
110+ const upload = multer ( { storage } ) ;
111+
112+ // Middleware
113+ app . use ( cors ( ) ) ;
114+ app . use ( express . json ( { limit : '50mb' } ) ) ;
115+ app . use ( express . urlencoded ( { extended : true , limit : '50mb' } ) ) ;
116+
117+ // Routes
118+ app . use ( '/api/leases' , leaseRoutes ) ;
119+ app . use ( '/api/owners' , ownerRoutes ) ;
120+ app . use ( '/api' , createPaymentRoutes ( database ) ) ;
121+
122+ app . get ( '/' , ( req , res ) => {
123+ res . json ( {
124+ project : 'LeaseFlow Protocol Backend' ,
125+ description : 'Secure Lease Indexer and Storage Facilitator' ,
126+ status : 'Operational' ,
127+ version : '1.0.0' ,
128+ contract_id : process . env . CONTRACT_ID || 'CAEGD57WVTVQSYWYB23AISBW334QO7WNA5XQ56S45GH6BP3D2AVHKUG4' ,
129+ endpoints : {
130+ upload_lease : 'POST /api/leases/upload' ,
131+ view_lease_handshake : 'GET /api/leases/:leaseCID/handshake' ,
132+ top_owners : 'GET /api/owners/top'
133+ }
134+ app . use ( express . json ( ) ) ;
135+ app . use ( '/uploads' , express . static ( path . join ( __dirname , 'uploads' ) ) ) ;
136+ const {
137+ createConditionProofService ,
138+ ConditionProofError,
139+ } = require ( './services/conditionProofService' ) ;
140+ const {
141+ createFileConditionProofStore,
142+ } = require ( './services/conditionProofStore' ) ;
143+
144+ const port = process . env . PORT || 3000 ;
83145 app . use ( express . json ( { limit : '50mb' } ) ) ;
84146 app . use ( express . urlencoded ( { extended : true , limit : '50mb' } ) ) ;
85147
@@ -253,6 +315,53 @@ if (require.main === module) {
253315 } ) . catch ( err => {
254316 console . warn ( 'AutoReclaimWorker failed to initialize:' , err . message ) ;
255317 } ) ;
318+ } ,
319+ ) ;
320+
321+ return app ;
322+ }
323+
324+ const app = createApp ( ) ;
325+
326+ if ( require . main === module ) {
327+ let scheduler ;
328+
329+ if ( config . jobs . renewalJobEnabled ) {
330+ const database = new AppDatabase ( config . database . filename ) ;
331+ const notificationService = new NotificationService ( database ) ;
332+ const sorobanLeaseService = new SorobanLeaseService ( config ) ;
333+ const leaseRenewalService = new LeaseRenewalService (
334+ database ,
335+ notificationService ,
336+ sorobanLeaseService ,
337+ config ,
338+ ) ;
339+ scheduler = startLeaseRenewalScheduler ( new LeaseRenewalJob ( leaseRenewalService ) , config ) ;
340+ }
341+
342+ const paymentTrackerDb = new AppDatabase ( config . database . filename ) ;
343+ const paymentTrackerService = new RentPaymentTrackerService ( paymentTrackerDb , {
344+ contractAccountId : config . contracts . defaultContractId ,
345+ } ) ;
346+ startPaymentTrackerJob ( paymentTrackerService , {
347+ cronExpression : process . env . PAYMENT_TRACKER_CRON || '* * * * *' ,
348+ } ) ;
349+
350+ app . listen ( port , ( ) => {
351+ console . log ( `LeaseFlow Backend running at http://localhost:${ port } ` ) ;
352+ console . log ( `Lease Encryption Service: Active` ) ;
353+ console . log ( `IPFS Storage Service: Initialized (Host: ${ process . env . IPFS_HOST || 'ipfs.infura.io' } )` ) ;
354+ console . log ( `LeaseFlow Backend listening at http://localhost:${ port } ` ) ;
355+ if ( scheduler ) {
356+ console . log ( `Lease renewal scheduler running every ${ config . jobs . intervalMs } ms` ) ;
357+ }
358+ const autoReclaimWorker = new AutoReclaimWorker ( ) ;
359+
360+ autoReclaimWorker . initialize ( ) . then ( ( ) => {
361+ autoReclaimWorker . start ( ) ;
362+ app . listen ( port , ( ) => {
363+ console . log ( `LeaseFlow Backend listening at http://localhost:${ port } ` ) ;
364+ console . log ( 'Auto-Reclaim Worker started' ) ;
256365 } ) ;
257366 } ) ;
258367}
0 commit comments