Manage Cross-Origin Resource Sharing In A Node With Hapi Application

To continue down my path of solving the worlds cross-origin resource sharing (CORS) problems, I wanted to adventure into Hapi, a Node.js framework that I’ve been heavily using lately. If you’re not familiar with cross-origin resource sharing, it is something that frequently comes up when you try to use front-end JavaScript to access content from another host or port.

Conclusion

You just saw how to enable and configure cross-origin resource sharing (CORS) in a Node.js application that uses Hapi as its framework. Enabling and configuring CORS is required when using browser-based JavaScript and backends that operate on different hosts or ports.

To see how to enable and configure CORS in an Express Framework application, check my tutorial here.

If you don’t have access to the backend, you can also force the browser to ignore CORS. Bypassing CORS via the browser can be seen in a previous article I wrote on the subject.

Nic Raboy

Nic Raboy is an advocate of modern web and mobile development technologies. He has experience in Java, JavaScript, Golang and a variety of frameworks such as Angular, NativeScript, and Apache Cordova. Nic writes about his development experiences related to making web and mobile development easier to understand.