File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ const express = require ( 'express' ) ;
2+ const bodyParser = require ( 'body-parser' ) ;
3+
4+ const app = express ( ) ;
5+ const PORT = process . env . PORT || 3000 ;
6+
7+ app . use ( bodyParser . json ( ) ) ;
8+
9+ // Mock data for recommendations
10+ const recommendations = [
11+ { title : "Use Organic Fertilizers" , details : "Organic fertilizers improve soil health and crop yield." } ,
12+ { title : "Implement Crop Rotation" , details : "Crop rotation helps in maintaining soil fertility." } ,
13+ { title : "Adopt Drip Irrigation" , details : "Drip irrigation conserves water and increases efficiency." }
14+ ] ;
15+
16+ // Endpoint to get recommendations
17+ app . get ( '/api/recommendations' , ( req , res ) => {
18+ res . json ( recommendations ) ;
19+ } ) ;
20+
21+ // Endpoint to get recommendation details
22+ app . post ( '/api/details' , ( req , res ) => {
23+ const { index } = req . body ;
24+ if ( index >= 0 && index < recommendations . length ) {
25+ res . json ( recommendations [ index ] ) ;
26+ } else {
27+ res . status ( 404 ) . json ( { error : 'Recommendation not found' } ) ;
28+ }
29+ } ) ;
30+
31+ app . listen ( PORT , ( ) => {
32+ console . log ( `Server is running on port ${ PORT } ` ) ;
33+ } ) ;
You can’t perform that action at this time.
0 commit comments