If a file is specified to serve instead of a directory, handle the error gracefully
Currently, if you erroneously specify a file instead of a directory to serve, the server crashes with the following error:
Jul 03 17:43:44 my-lovely-demo.site site[32756]: (node:32756) UnhandledPromiseRejectionWarning: Error: ENOTDIR: not a directory, scandir '/home/aral/public/index.html'
Jul 03 17:43:44 my-lovely-demo.site site[32756]: at Object.readdirSync (fs.js:872:3)
Jul 03 17:43:44 my-lovely-demo.site site[32756]: at Object.readdirSync (/usr/local/bin/site:181:50)
Jul 03 17:43:44 my-lovely-demo.site site[32756]: at Site.addHugoSupport (/usr/local/bin/index.js:443:22)
Jul 03 17:43:44 my-lovely-demo.site site[32756]: at Site.configureAppRoutes (/usr/local/bin/index.js:554:16)
Jul 03 17:43:44 my-lovely-demo.site site[32756]: at Site.configureApp (/usr/local/bin/index.js:295:18)
Jul 03 17:43:44 my-lovely-demo.site site[32756]: at Site.serve (/usr/local/bin/index.js:855:16)
Jul 03 17:43:44 my-lovely-demo.site site[32756]: at processTicksAndRejections (internal/process/task_queues.js:97:5)
Jul 03 17:43:44 my-lovely-demo.site site[32756]: at async /usr/local/bin/bin/commands/serve.js:287:9
Jul 03 17:43:44 my-lovely-demo.site site[32756]: (node:32756) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
Jul 03 17:43:44 my-lovely-demo.site site[32756]: (node:32756) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Let’s handle this more gracefully :)