Skip to content

Commit

Permalink
Makes Experience API more formal
Browse files Browse the repository at this point in the history
  • Loading branch information
rspurgeon committed Sep 19, 2023
1 parent 4ec7ded commit 07584b8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
1 change: 1 addition & 0 deletions PORTS.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ KONG_AIR_FLIGHTS_PORT=8080
KONG_AIR_ROUTES_PORT=8081
KONG_AIR_BOOKINGS_PORT=8082
KONG_AIR_CUSTOMER_PORT=8083
KONG_AIR_EXPERIENCE_PORT=8084
8 changes: 7 additions & 1 deletion experience/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ check-dependencies:
@$(call check-dependency,node)
@$(call check-dependency,npm)

test: check-dependencies
npm run test

build: check-dependencies
npm install

run: check-dependencies
npm run start
node index.js ${KONG_AIR_EXPERIENCE_PORT}

24 changes: 18 additions & 6 deletions experience/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,32 @@ const FlightsAPI = require('./datasources/flights-api');
require('dotenv').config()

async function startApolloServer() {
const server = new ApolloServer({ typeDefs, resolvers });
const server = new ApolloServer({
typeDefs,
resolvers,
dataSources: () => ({
customerAPI: new CustomerAPI(),
bookingsAPI: new BookingsAPI(),
routesAPI: new RoutesAPI(),
flightsAPI: new FlightsAPI(),
}),
});

const port = process.argv[2] || 4000; // Getting port from command line arguments, with a default value of 4000

const { url } = await startStandaloneServer(server, {
context: async ( { req } ) => {
context: async ({ req }) => {
const { cache } = server;
return {
dataSources: {
customerAPI: new CustomerAPI( req, { cache } ),
bookingsAPI: new BookingsAPI( req, { cache } ),
routesAPI: new RoutesAPI( { cache } ),
flightsAPI: new FlightsAPI( { cache } ),
customerAPI: new CustomerAPI(req, { cache }),
bookingsAPI: new BookingsAPI(req, { cache }),
routesAPI: new RoutesAPI({ cache }),
flightsAPI: new FlightsAPI({ cache }),
},
};
},
listen: { port: port },
});

console.log(`
Expand Down
10 changes: 10 additions & 0 deletions kill-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,13 @@ then
else
echo "No bookings service pid found"
fi

if [[ -f "./experience/experience.pid" ]];
then
pid=$(cat ./experience/experience.pid)
echo "Killing experience service $pid"
kill $pid
rm -f ./experience/experience.pid
else
echo "No experience service pid found"
fi
9 changes: 9 additions & 0 deletions run-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,12 @@ echo "Bookings process ID:" $(cat ./bookings.pid)
echo "------------------------------------"
popd

pushd ./experience
echo "Running experience service"
make build
node ./index.js "$KONG_AIR_EXPERIENCE_PORT" > /tmp/experience.log 2>&1 &
echo $! > ./experience.pid
echo "Experience process ID:" $(cat ./experience.pid)
echo "------------------------------------"
popd

0 comments on commit 07584b8

Please sign in to comment.