What is Rack::Cors
What is Rack? What is Cors? How do they interact with one another?
“rack-cors” is a gem that you will see and use often. But what is it and what does it do? To know exactly what this gem does, you’ll need some foundational information about both “Rack” and CORS, what they represent and how they work together when implemented in your application.
“Rack” refers to the foundation of technology, an abstraction, upon which nearly all Ruby frameworks are based. There are a few different components of Rack. One, it is a simple architecture that allows one to build reusable chunks of code that can then be implemented into a larger application, as long as it is compliant with the rules of Rack’s interface. Rack also refers to the gem itself. The Rack gem contains the Rack architecture and allows us to write code within its framework.
Rack Compliant Code
In order for code to comply with the Rack framework it must have the following characteristics:
- It must respond to the command “call.”
- The “call” method must accept a single argument. The argument goes by env or environment and acts as a bundler for all of the data in the “call” request.
3. The “call” method has to return an array of three things: status, headers and body.
The term middleware refers to any software that “acts as a bridge” between a database, or an operating system and the application. Middleware can be used and nested to create larger applications using the Rack pattern and framework.
“CORS” specifically stands for Cross-Origin Resource Sharing. It is essentially a system of HTTP Headers that transmit signals and determine whether browsers will receive or block frontend code from getting responses for cross-origin requests. CORS functions by adding new headers that let servers determine which origins are permitted to read that information from a given browser. You can do further reading about the specific CORS headers here.
When working in concert with one another as the rack-cors gem, the two make up a Middleware that make CORS-compatible Rack-framework applications.
Rack::Cors provides support for Cross-Origin Resource Sharing (CORS) for Rack compatible web applications. The CORS…
Upcase : What is Rack? | Ruby on Rails Tutorial by thoughtbot
Rack is the underlying technology behind nearly all of the web frameworks in the Ruby world. "Rack" is actually a few…