Freeze-in production of dark matter through spin-1 and spin-2 portals