Attach api endpoints to functions, add CORS support