import express from 'express' ; const recommendations = require ( '../data/recommendations.json' ) ; import { HttpServer } from '@loopback/http-server' ; import { ParamsDictionary } from 'express-serve-static-core' ; export function createRecommendationServer ( port = 3001 , host = undefined ) { const app = express ( ) ; app . get ( '/:userId' , ( req , res ) => { let userId = ( req . params as ParamsDictionary ) . userId || 'user001' ; if ( ! ( userId in recommendations ) ) { userId = 'user001' ; } res . send ( recommendations [ userId ] || [ ] ) ; } ) ; return new HttpServer ( app , { port , host } ) ; } export async function restMain ( port = 3001 , host = undefined ) { const server = createRecommendationServer ( port , host ) ; await server . start ( ) ; console . log ( 'Recommendation REST server is running at ' + server . url + '.' ) ; return server ; }