Resonator mode matching for free-electron-laser optical guiding