Skip to content

Commit

Permalink
Actualiza a rails 7.1, esbuild 0.19 y msip 2.2.0.beta4. Ver https://g…
Browse files Browse the repository at this point in the history
  • Loading branch information
vtamara committed Jan 29, 2024
1 parent 2d55213 commit ee84b67
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 119 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ gem "prawnto_2", :require => "prawnto"

gem "prawn-table"

gem "rack"
gem "rack", "~> 2"

gem "rack-cors"

gem "rails", ">= 7.0", "< 7.1"
gem "rails", ">= 7.1", "<7.2"
#git: "https://github.com/rails/rails.git", branch: "6-1-stable"

gem "rails-i18n"
Expand Down
13 changes: 10 additions & 3 deletions config.ru
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# frozen_string_literal: true

# This file is used by Rack-based servers to start the application.

require_relative "config/environment"

run Rails.application
Rails.application.load_server
rutarel = ENV.fetch("RUTA_RELATIVA", "msip/")
if rutarel[0] != '/'
rutarel = "/" + rutarel
end
map rutarel do
run Rails.application
Rails.application.load_server
end
20 changes: 18 additions & 2 deletions config/application.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
require_relative 'boot'
require 'rails/all'
require "rails"
# Elige los marcos de trabajo que necesitas:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
# require "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
# require "action_mailbox/engine"
# require "action_text/engine"
require "action_view/railtie"
# require "action_cable/engine"
require "rails/test_unit/railtie"


# Requiere gemas listas en el Gemfile, incluyendo las
# limitadas a :test, :development, o :production.
Expand All @@ -8,7 +21,10 @@
module Sivel2
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
config.load_defaults 7.0
config.load_defaults Rails::VERSION::STRING.to_f

config.autoload_lib(ignore: %w(assets tasks))


config.action_view.form_with_generates_remote_forms = false

Expand Down
15 changes: 9 additions & 6 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# In the development environment your application's code is reloaded any time
# it changes. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
config.enable_reloading = true

# Do not eager load code on boot.
config.eager_load = false
Expand All @@ -33,9 +33,6 @@
config.cache_store = :null_store
end

# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false

Expand All @@ -56,6 +53,9 @@
# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = true

# Highlight code that enqueued background job in logs.
config.active_job.verbose_enqueue_logs = true

# Suppress logger output for asset requests.
config.assets.quiet = true

Expand All @@ -65,6 +65,9 @@
# Annotate rendered view with file names.
# config.action_view.annotate_rendered_view_with_filenames = true

# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true
# Raise error when a before_action's only/except options reference missing actions
config.action_controller.raise_on_missing_callback_actions = true

config.web_console.permissions = ENV.fetch("WEB_CONSOLE_PERMISSIONS", "").
split(",")
end
62 changes: 29 additions & 33 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Settings specified here will take precedence over those in config/application.rb.

# Code is not reloaded between requests.
config.cache_classes = true
config.enable_reloading = false

# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
Expand All @@ -13,16 +13,15 @@
config.eager_load = true

# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.consider_all_requests_local = false
config.action_controller.perform_caching = true

# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
# Ensures that a master key has been made available in ENV["RAILS_MASTER_KEY"], config/master.key, or an environment
# key such as config/credentials/production.key. This key is used to decrypt credentials (and other encrypted files).
# config.require_master_key = true

# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
# Disable serving static files from `public/`, relying on NGINX/Apache to do so instead.
# config.public_file_server.enabled = false

# Compress CSS using a preprocessor.
# config.assets.css_compressor = :sass
Expand All @@ -37,30 +36,32 @@
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache
# config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX

# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local

# Mount Action Cable outside main process or domain.
# config.action_cable.mount_path = nil
# config.action_cable.url = "wss://example.com/cable"
# config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ]
# Assume all access to the app is happening through a SSL-terminating reverse proxy.
# Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies.
# config.assume_ssl = true

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
config.force_ssl = true

# Include generic and useful information about system operation, but avoid logging too much
# information to avoid inadvertent exposure of personally identifiable information (PII).
config.log_level = :info
# Log to STDOUT by default
config.logger = ActiveSupport::Logger.new(STDOUT)
.tap { |logger| logger.formatter = ::Logger::Formatter.new }
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }

# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]

# Info include generic and useful information about system operation, but avoids logging too much
# information to avoid inadvertent exposure of personally identifiable information (PII). If you
# want to log everything, set the level to "debug".
config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info")

# Use a different cache store in production.
# config.cache_store = :mem_cache_store

# Use a real queuing backend for Active Job (and separate queues per environment).
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "sivel2_production"
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "dummy_production"

config.action_mailer.perform_caching = false

Expand All @@ -75,19 +76,14 @@
# Don't log any deprecations.
config.active_support.report_deprecations = false

# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new

# Use a different logger for distributed setups.
# require "syslog/logger"
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name")

if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end

# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false

# Enable DNS rebinding protection and other `Host` header attacks.
# config.hosts = [
# "example.com", # Allow requests from example.com
# /.*\.example\.com/ # Allow requests from subdomains like `www.example.com`
# ]
# Skip DNS rebinding protection for the default health check endpoint.
# config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
end
23 changes: 12 additions & 11 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

# Turn false under Spring and add config.action_view.cache_template_loading = true
config.cache_classes = true
# While tests run files are not watched, reloading is not necessary.
config.enable_reloading = false

# Eager loading loads your whole application. When running a single test locally,
# this probably isn't necessary. It's a good idea to do in a continuous integration
# system, or in some way before deploying your code.
# Eager loading loads your entire application. When running a single test locally,
# this is usually not necessary, and can slow down your test suite. However, it's
# recommended that you enable it in continuous integration systems to ensure eager
# loading is working properly before deploying your code.
config.eager_load = ENV["CI"].present?

# Configure public file server for tests with Cache-Control for performance.
Expand All @@ -23,19 +24,16 @@
}

# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.cache_store = :null_store

# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false
# Render exception templates for rescuable exceptions and raise for other exceptions.
config.action_dispatch.show_exceptions = :rescuable

# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false

# Store uploaded files on the local file system in a temporary directory.
config.active_storage.service = :test

config.action_mailer.perform_caching = false

# Tell Action Mailer not to deliver emails to the real world.
Expand All @@ -57,4 +55,7 @@

# Annotate rendered view with file names.
# config.action_view.annotate_rendered_view_with_filenames = true

# Raise error when a before_action's only/except options reference missing actions
config.action_controller.raise_on_missing_callback_actions = true
end
14 changes: 7 additions & 7 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


rutarel = ENV.fetch('RUTA_RELATIVA', 'sivel2/')
scope rutarel do


devise_scope :usuario do
get 'sign_out' => 'devise/sessions#destroy'
Expand Down Expand Up @@ -45,12 +45,12 @@
:as => 'mapatiempocovid'

root 'sivel2_gen/hogar#index'
end # scope
# scope

mount Msip::Engine, at: rutarel, as: 'msip'
mount Mr519Gen::Engine, at: rutarel, as: 'mr519_gen'
mount Heb412Gen::Engine, at: rutarel, as: 'heb412_gen'
mount Sivel2Gen::Engine, at: rutarel, as: 'sivel2_gen'
mount Apo214::Engine, at: rutarel, as: 'apo214'
mount Msip::Engine, at: "/", as: 'msip'
mount Mr519Gen::Engine, at: "/", as: 'mr519_gen'
mount Heb412Gen::Engine, at: "/", as: 'heb412_gen'
mount Sivel2Gen::Engine, at: "/", as: 'sivel2_gen'
mount Apo214::Engine, at: "/", as: 'apo214'

end
46 changes: 0 additions & 46 deletions esbuild-des.config.js

This file was deleted.

62 changes: 62 additions & 0 deletions esbuild-des.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Recarga viva (live reloading) durante desarrollo
// Recompila automáticamente ante cambios en javascript de app/javascript
// y refresca automáticamente en navegador
// Basado en https://www.colby.so/posts/live-reloading-with-esbuild-and-rails

import * as path from "path"
import * as http from "http"

const watch = process.argv.includes('--watch')
const clients = []

const watchOptions = {
onRebuild: (error, result) => {
if (error) {
console.error('Falló construcción:', error)
} else {
console.log('Construcción exitosa')
clients.forEach((res) => res.write('data: update\n\n'))
clients.length = 0
}
}
}

import * as esbuild from 'esbuild'

if (watch && watchOptions) {
let ctx = await esbuild.context({
entryPoints: ['application.js'],
bundle: true,
preserveSymlinks: true,
outdir: path.join(process.cwd(), "app/assets/builds"),
absWorkingDir: path.join(process.cwd(), "app/javascript"),
banner: {
js: ` (() => new EventSource("http://${process.env.MAQRECVIVA}:${process.env.PUERTORECVIVA}").onmessage = () => location.reload())();`,
}
})
await ctx.watch()
} else {
let result = esbuild.build({
entryPoints: ["application.js"],
bundle: true,
preserveSymlinks: true,
outdir: path.join(process.cwd(), "app/assets/builds"),
absWorkingDir: path.join(process.cwd(), "app/javascript"),
banner: {
js: ` (() => new EventSource("http://${process.env.MAQRECVIVA}:${process.env.PUERTORECVIVA}").onmessage = () => location.reload())();`,
}
}).catch(() => process.exit(1));
console.log(result);
}

http.createServer((req, res) => {
return clients.push(
res.writeHead(200, {
"Content-Type": "text/event-stream",
"Cache-Control": "no-cache",
"Access-Control-Allow-Origin": "*",
Connection: "keep-alive",
}),
);
}).listen(process.env.PUERTORECVIVA, process.env.IPDES);

Loading

0 comments on commit ee84b67

Please sign in to comment.