Fixes /api and public routing and adds error handling.