Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

read-only-mode

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

read-only-mode

  • 1.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Read Only Mode

A simple ruby gem for adding read only maintenance mode to your Rails / Rack applications.

When read only mode is enabled, all non GET / HEAD requests will be rejected with a 503 Service Unavailable response. Additionally the 503 response will be given in case a GET request would raise a PG::ReadOnlySqlTransaction error.

Installation

Add the line to your application's Gemfile:

gem "read_only_mode"

Usage

Read only mode is enabled via environment variables. There are two options, either:

Set READ_ONLY_MODE=true

Or...

Set PGOPTIONS="-c default_transaction_read_only=on" (or any other string containing default_transaction_read_only=on).

The PGOPTIONS approach is recommended for applications using Postgres as this will prevent any write queries from being executed.

Rack integration

Rails applications will automatically use the middleware via a Railtie. For other Rack applications, you can add the middleware manually:

use ReadOnlyMode::Middleware if ReadOnlyMode.enabled?

Configuration

You can customize the HTML / JSON responses returned when read only mode is enabled via some simple setters:

ReadOnlyMode.html_response = File.read("path/to/your/read_only.html")
ReadOnlyMode.json_response = { error: "Maintenance in progress" }.to_json

FAQs

Package last updated on 06 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc