added messaging middleware to ap.js