I run an web app localhost using Rails5, Puma webserver, and forwardHQ for my localhost testing, such that fizzbuzz.dev is the Internet address. My webpack+React App renders and the Chrome dev console is relatively clean if I use Webpack 3 to compile things on the fly, no dev server. If I switch to using a Procfile.dev and foreman with the line:
webpacker: ./bin/webpack-dev-server
the App continues to run, but the console fills with XHR calls to some sockjs-node/info call that fails. Maybe 4 or 5 of those. What are they? Is that something I should care about? It seems my App runs nonetheless, but a messy console is not something I like.
Any tips on how to fix it so this bad XHR calls turns into a success? What would change if it did work?
My webpacker yaml setup is:
development:
<<: *default
compile: true
dev_server:
https: true
host: 0.0.0.0
port: 3035
public: 0.0.0.0:3035
hmr: false
# Inline should be set to true if using HMR
inline: true
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: /node_modules/
I tried using localhost for 0.0.0.0, same result. Not sure how to resolve this. Tried without HTTPS too but that also failed.
Related
I'm new to webpack and clearly missing something here. This seemed to be working until we upgraded our app to rails 6.1 and webpacker 5.4. yarn --version webpack outputs 1.22.10
Everything appears to get served correctly in the development environment. In the test environment some assets appear to get served(like some images and some react templates) but no styles are served and the app is totally unstyled.
One thing I noticed is that if I leave webpack-dev-server off in development mode, I get the same issue as test gets. This makes me think that the test env is not configured properly to work with webpack-dev-server but so far I cannot figure out how to connect them
The app has assets in two locations: app/assets and app/frontend
One interesting thing that I noticed is that the public/packs directory looks very different from the public/packs-test directory` although I can't see any reason why that should be true.
public/packs has a single file in it : manifest.json
public/packs-test has a ton of chunk files in it
Here is the relevant config
webpacker.yml
---
# Note: You must restart bin/webpack-dev-server for changes to take effect
default: &default
source_path: app/frontend
source_entry_path: packs
public_output_path: packs
cache_path: tmp/cache/webpacker
resolved_paths: ['app/assets', 'vendor/assets']
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false
extensions:
- .erb
- .jsx
- .js
- .sass
- .scss
- .css
- .module.sass
- .module.scss
- .module.css
- .png
- .svg
- .gif
- .jpeg
- .jpg
- .json
development:
<<: *default
compile: true
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: true
host: localhost
port: 3035
public: localhost:3035
hmr: true
# Inline should be set to true if using HMR
inline: true
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: /node_modules/
aggregateTimeout: 300
poll: 500
test:
<<: *default
compile: true
public_output_path: packs-test
production: &production
<<: *default
compile: false
cache_manifest: true
webstaging:
<<: *production
webtest:
<<: *production
webdev:
<<: *production
config/webpack/environment.js
const { environment } = require('#rails/webpacker')
const erbLoader = require('./loaders/erb')
const svgLoader = require('./loaders/svg')
const addCommonsChunkPlugins = require('./plugins/commons-chunk')
const injectIndividualStylesheets = require('./individual-stylesheets')
// Set shorter hashes
environment.config.set('output.filename', '[name]-[hash:6].js')
environment.config.set('output.chunkFilename', '[name]-[chunkhash:6].chunk.js')
// More readable classnames for css modules
const cssLoader = environment.loaders
.get('moduleCss')
.use.find(el => el.loader === 'css-loader')
cssLoader.options.localIdentName = '[local]_[hash:base64:5]'
// Manually add any ES6 targeted vendor dependencies
// converts /node_modules/ to /node_modules(?!\/my-es6-targeted-module)/
const babelLoader = environment.loaders.get('babel')
const newExcludePattern = new RegExp(`${babelLoader.exclude.source}(?!\/better-youtube-api)`)
babelLoader.exclude = newExcludePattern
// Add erb loader (for images.js.erb)
environment.loaders.append('erb', erbLoader)
// Load svg files differently from css and js files
environment.loaders.insert('svg', svgLoader, { after: 'file' })
// Exclude svg extension from file loader
const fileLoader = environment.loaders.get('file')
fileLoader.exclude = /\.(svg)$/i
// Add commons chunk plugin for extracting common shared modules
addCommonsChunkPlugins(environment)
// Add individual stylesheets to webpack entries
injectIndividualStylesheets(environment)
module.exports = environment
config/webpack/development.js
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
const environment = require('./environment')
module.exports = environment.toWebpackConfig()
config/webpack/test.js
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
const environment = require('./environment')
module.exports = environment.toWebpackConfig()
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
config.action_mailer.default_url_options = { host: "localhost", port: 3000 }
Rails.application.routes.default_url_options[:host] = 'localhost:3000'
config.force_ssl = true
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
# Do not eager load code on boot. This avoids loading your whole application
# just for the purpose of running a single test. If you are using a tool that
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false
# Configure public file server for tests with Cache-Control for performance.
config.public_file_server.enabled = true
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}"
}
# Separate file storage in the test environment
config.active_storage.service = :test
# Use inline job processing to make things happen immediately
config.active_job.queue_adapter = :inline
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false
# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = true
config.action_mailer.perform_caching = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
config.x.enable_gtm = false
end
I would be extremely grateful for any insite as I have been fighting this for a while
I still don't really know what was going on here or if it was resolvable but upgrading my webpack (not webpacker) version along with many sub dependencies solved this for me.
I'm using Rails 6 with webpacker on a remote server.
When running bin/webpack-dev-server, it returns :
ℹ 「wds」: Project is running at https://MY_HOST:3035/
ℹ 「wds」: webpack output is served from /packs/
ℹ 「wds」: Content not from webpack is served from /PATH/public/packs
ℹ 「wds」: 404s will fallback to /index.html`
When visiting the URL, the pack URL returns a 404 error :
https://MY_HOST/packs/js/application-HASH.js net::ERR_ABORTED 404 (Not Found)
It works fine when I'm using bin/webpack --watch
Here is the dev_server configuration :
dev_server:
https: true
host: '0.0.0.0'
port: 3035
public: MY_HOST:3035
hmr: false
# Inline should be set to true if using HMR
inline: true
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
pretty: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: '**/node_modules/**'
The manifest.json hashes are the same as what the webpack dev server generates.
I can't seem to understand what is the issue.
I would really appreciate any pointers.
I have a Rails app deployed to Heroku and I cant for the life of me figure out why it keeps wanting to deploy to the local. I do not even have localhost:6379 anywhere in my code for the front end (react native) or the back end which is my Rails API.
This is the error I get any time I have a new broadcast:
Completed 500 Internal Server Error in 111ms (ActiveRecord: 47.1ms)
Redis::CannotConnectError (Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)):
Application.yaml:
`gmail_username: "<email_address>"
gmail_password: "<password>"
AWS_ACCESS_KEY: "<access_key>"
AWS_SECRET_KEY: "<secret_key>"
AWS_BUCKET: "<my_s3_app_bucket>"
REDIS_URL: "<redis_url>"`
Cable.yaml
production:
adapter: redis
url: <long_url_address>
host: <host_from_url>
port: <port_from_url>
password: <password_from_url>
Production.rb:
config.action_cable.allowed_request_origins = ["https://lynx-v1.herokuapp.com/"]
config.action_cable.url = "wss://lynx-v1.herokuapp.com/cable"
config.web_socket_server_url = "wss://lynx-v1.herokuapp.com/cable"
(i set both action cable and web socket just to test which worked, no matter which i go with i still get the error)
/config/initializers/redis.rb
require "redis"
uri = URI.parse(ENV["REDIS_URL"])
$redis = Redis.new(
:url => ENV["REDIS_URL"],
)
I dont know what is going on. Is it some kind of default that makes Redis look for local host 6379? I follow the steps step by step and I keep getting this error.
It started working again. There was an add-on gem in the rails app that was not fully configured. After finishing the setup for the side gem it started working again.
I'm trying to send custom metrics to NewRelic insights, but unfortunately it is not working for my Rails app that is currently sending default data to New Relic.
Steps to reproduce
I just logged in the console of the working application and ran the following command:
NewRelic::Agent.record_metric('/Custom/MyCategory/MyMetric', 5)
Unfortunately it never appeared in the Insights Data Explorer.
The configuration in the application is the following:
common: &default_settings
license_key: <MY_KEY>
app_name: my_app
log_level: info
development:
<<: *default_settings
app_name: executive_alerts (development)
monitor_mode: false
test:
<<: *default_settings
app_name: executive_alerts (test)
monitor_mode: false
staging:
<<: *default_settings
app_name: executive_alerts (staging)
production:
<<: *default_settings
Thank you!
From the documentation for the New Relic agent:
http://www.rubydoc.info/github/newrelic/rpm/NewRelic/Agent#record_metric-instance_method
https://github.com/newrelic/rpm/blob/c252fad410a5d41a65a827d633338af609f8dff6/lib/new_relic/agent.rb#L143-L144
metric_name should follow a slash separated path convention. Application specific metrics should begin with Custom/.
Change your command from:
NewRelic::Agent.record_metric('/Custom/MyCategory/MyMetric', 5)
to:
NewRelic::Agent.record_metric('Custom/MyCategory/MyMetric', 5)
I've got a module named content, and its in the app frontend. When I go to localhost:8080/frontend_dev.php/content , I get the page showing up just fine without errors. But without the /frontend_dev.php I cant access the page.
What can be wrong? Here is my frontend settings.yml:
prod:
.settings:
no_script_name: true
logging_enabled: false
dev:
.settings:
error_reporting:
web_debug: true
cache: false
no_script_name: false
etag: false
test:
.settings:
error_reporting:
cache: false
web_debug: false
no_script_name: false
etag: false
all:
.settings:
# Form security secret (CSRF protection)
csrf_secret: ecca0f5ffb475363f798d55871546583f60f971f
# Output escaping settings
escaping_strategy: true
escaping_method: ESC_SPECIALCHARS
# Enable the database manager
use_database: true
enable_modules: [default, sfGuardAuth]
What I get is a 404 from the web server. Cleared the symfony cache, did not work. And did a chown -R username projectdirectory.
The address I mean is localhost:8080/module/action , does not work for anything. But it works like that on another server I'm running a symfony project.
EDIT:
I'm still new to symfony. I managed to enter with localhost:8080/index.php/module/action . But how can I remove the index.php from the routing rules? Thanks
Thanks
It sounds like mod_rewrite isnt fired up, do you have it enabled? Is it even installed?
You can check with:
/your/path/to/httpd -M | grep rewrite
Or you could remove the <IfModule mod_rewrite.c></IfModule> tags around the rewrite rules in .htaccess. After doing this apache will generate a configuration error if mod_rewrite isnt installed and/or enabled.
If you have mod rewrite installed then make sure its directives can be used from .htaccess You should have something like the following in your vhost (or httpd.conf):
<Directory "/path/to/your/project/web">
AllowOverride All
# possibly other rules....
</Directory>