Workbox will not load - service-worker

I'm trying to use Workbox to add PWA functionality to my website. I'm following the Get Started guide, but I'm not getting far. When I run the website in Chrome I get the following error:
Refused to load the script 'https://storage.googleapis.com/workbox-cdn/releases/3.6.1/workbox-sw.js' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval'".
Per the docs, I am importing workbox-sw.js in my service worker file that is in my wwwroot folder with the following line:
importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.6.1/workbox-sw.js');
The "Refused to load..." error occurs on that import statement.
How can I get rid of this error?

You have a CSP configuration that prevents loading scripts from third-party origins and then you are trying to load a script from Google. You either need to allow the script to load or load the page from your site.
Update the CSP header to allow the Google domain by adding script-src 'self' 'unsafe-eval' https://storage.googleapis.com.
Using Local Workbox Files Instead of CDN

Related

Dart webdev server and PHP files

I'm developing a web project with Google Dart SDK version 2.2 and using PhpStorm as my IDE. The project is intended to start with a index.php file which does some preliminary server side work at the end of which is a call to include('project1.html'); which downloads the html file to the client and includes <script defer src="project1.dart.js"></script> at the end. I'm trying to figure out the best setup for development. I have php installed on the development machine and included in the path.
I have found that calling webdev serve from the terminal serves the project to http://localhost:8080 but displays Could not find web/index.html instead of the expected rendering of project1.html. So I guess the webdev server does not handle .php files?
Another approach is to right click the index.php file and select run in browser. This brings up a Chrome page displaying the text of the index.php file. So again php not processed I guess.
Another approach is to set up a javascript debug configuration with default settings and clicking the green debug icon. This does produces the correct project1.index output and the index.php has been correctly processed. However, I cannot get breakpoints to work and errors in the Chrome Dev Console refer to the project1.dart.js file in the build directory.
Another approach I tried is using an Xampp server to serve the files. In this case I had a number of projects and set each up under xampp/htdocs i.e. xampp/htdcos/project1 etc. In PhpStorm I set up a local or mounted server with:
folder C:\xampp\htdocs\project1,
webserver root url http://localhost/project1,
local path pointing to the web subdirectory of my project, and
deployment and webpaths both set to \.
PhpStorm seems to work ok but again breakpoints did not work and debug error messages did not refer to the dart files.
Any help would be most welcome. Is what I am trying to do even possible with this setup i.e. starting with an index.php file?
** EDIT **
Following advice below, I added following to my httpd-vhosts.conf file:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/project1"
ServerName localhost
ProxyPreserveHost On
ProxyRequests Off
ProxyPassMatch ^/(.*\.js)$ http://localhost:8080/$1
</VirtualHost>
Then I keep my .php files and MySql on Xampp and javascript is served by webdev serve.
However, I have the same problem i.e. breakpoints in PhpStorm or Chrome dev tools source Dart files don't trigger and Chrome dev tools console refers to javascript files instead of Dart source.
You need to run a reverse proxy on the apache/php server and redirect js requests to webdev server, then you just run your application testing using the apache/php server and any browser. When you go to deploy, use dart2js to generate the js files and copy the whole build directory where it can be read by a normal apache/php server (i.e. no reverse proxy).

Internal Server Error when running running yajra datatable using php artisan serve

I'm new in Laravel and I would like to ask for guidance for the datatables tutorial.
I tried to follow the laravel datatables tutorial from the link I provided below and I kept on encountering the issue below.
Laravel Datatables Link:
https://appdividend.com/2018/04/16/laravel-datatables-tutorial-with-example/
DataTables warning: table id=table – Ajax error. For more information about this error, please see http://datatables.net/tn/7
I tried to change the providers and aliases from the config as instructed. I also went to the Web Developer > Network by clicking ctrl+shift+E in firefox, I went to xhr and I saw that its returning 500 Internal Server Error. Could you please guide me on how to fix this.
I am using php artisan serve to run the web page as instructed on the tutorial but according to the github link the artisan serve should be avoided.
github link: https://github.com/yajra/laravel-datatables

HTTP parse error, malformed request - Ruby on Rails

I see the following error in Terminal when attempting to run a Ruby on Rails app.
HTTP parse error, malformed request (): #<Puma::HttpParserError: Invalid HTTP format, parsing fails.>
2017-03-12 13:10:02 -0400: ENV: {"rack.version"=>[1, 3], "rack.errors"=>#<IO:<STDERR>>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "SCRIPT_NAME"=>"", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"puma 3.4.0 Owl Bowl Brawl", "GATEWAY_INTERFACE"=>"CGI/1.2"}
The browser error:
This site can’t provide a secure connection. localhost sent an invalid response. ERR_SSL_PROTOCOL_ERROR*
I have tried the following
Clearing browser cache and restarting
Reverting back to an old commit in GIT that was working at the time
Restarting terminal
Running a different rails app that was functional
Here are some possible solutions.
Make sure you are connecting through http://localhost:3000 and not https://localhost:3000.
If the browser redirects to HTTPS and it's Google Chrome, try this solution that addresses an HSTS problem: https://stackoverflow.com/a/28586593
Make sure you do not have the production environment (if that's what you're serving) forcing HTTPS. If that's the problem, comment this out or change true to false:
config/environments/production.rb
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true
seems like you are trying to run HTTPS on your local. You need to have a TLS toolkit (like openSSL) installed on your local.
OPENSSL for example.
after you made sure of that, and if still not working, maybe you can find you're answer in the next Github issue. Seems like a bug with Puma gem.
GITHUB ISSUE TALK
For those reading this in the future, consider the following:
Did you change your server in your Gemfile. e.g. from Puma to Thin?
Have you set up an SSL certificate?
Are you starting your webserver with SSL certificate flags?
Is SSL turned on in your development/production environment - and what environment are you invoking?
If you are ok with turning off SSL in your development environment you can do so by going to:
config/environments/development.rb and configuring:
config.force_ssl = false
Here is some code that works for me, using puma, that invokes SSL certification (locally). I have created my certificates and have dumped it in the relevant location:
rails s -b 'ssl://localhost:3000?key=./.ssl/localhost.key&cert=./.ssl/localhost.crt'
When I want to run it in a production environment from my PC I using the following:
rails s -b 'ssl://localhost:3000?key=./.ssl/localhost.key&cert=./.ssl/localhost.crt' -e production
HTH
Access the app using a different browser, or if you are in Chrome access it in Incognito mode. After this the error did not show in any browser again. Remember to remove the config.force_ssl or set it to false in the development.rb file first.
Encountered this today after adding and then removing the config.force_ssl = true config in our Rails 6 app's development.rb file. Tried to access the app in localhost, in a Chrome browser, and the same error showed. Restared rails server several times, to no avail.
The accessing it in different browser, where the force ssl version of the app client was never opened, worked.
In my case it was silly mistake I started server on http and my url was pointing to https.
I hope it would save someone's time ;)
Faced this error as well,
If the above solutions don't work, do a quick check to see if you have this meta tag in your application.html.erb
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
This will force Google Chrome to redirect localhost to HTTPS
If you are setting Content-Security-Policy in your application via action_dispatch.default_headers:
config.action_dispatch.default_headers = ({
'Content-Security-Policy' => "default-src 'self' https:;\
font-src 'self' https: data:;\
img-src 'self' https: data: blob:;\
object-src 'self';\
script-src 'self' https: 'unsafe-inline' 'unsafe-eval';\
style-src 'self' https: 'unsafe-inline';\
upgrade-insecure-requests;\
frame-ancestors *"
})
Make sure to override that setting in your development environment to add http: options to these. Like so:
config.action_dispatch.default_headers = ({
'Content-Security-Policy' => "default-src 'self' http: https:;\
font-src 'self' http: https: data:;\
img-src 'self' http: https: data: blob:;\
object-src 'self';\
script-src 'self' http: https: 'unsafe-inline' 'unsafe-eval';\
style-src 'self' http: https: 'unsafe-inline';\
frame-ancestors *"
})

404 on Openshift URL, URL fine on dev

I have a website that I am developing locally and pushing to RH Openshift with a PHP-5.4 and MySQL cartridge.
Most URL's work, but I am having an issue with some page URL's being recognised locally, but returning a 404 on Openshift.
Example: on development the following URL works: local.development.local/public/reset.php but visiting the Openshift url: example.rhcloud.com/public/reset.php returns a 404. However, example.rhcloud.com/reset.php works, even though reset.php is within the public folder directory.
The folder structure is the exact same on development as it is within Openshift repo folder.
Is there a specific setting I need to set in my Openshift environment to get it to recognize the URL?
The problem was due to the directory structure I had given my website. Since I had placed the majority of my code within a folder named public, Openshift was using that as the DocumentRoot. This wasn't my required functionality, so I renamed the folder to app, updated my URL's and this resolved the issue. Blog post giving the Openshift DocumentRoot logic can be found here: https://blog.openshift.com/openshift-online-march-2014-release-blog/

Converting Ember Rails app to phonegap

I have just start using both Ember and Phonegap and I am using the Ruby on Rails Ember-Rails gem as wanted to use Rails to do the asset pre-compilation. I can use rails s to run the Ember app and all works fine. To get into a phonegap app, I am doing a rake assets:precompile command, then copying the fingerprinted css and js files to an assets directory and modifying the index/html file to pick them up as follows:
<!DOCTYPE html>
<html>
<head>
<title>MahimanagerPhoneApp</title>
<link rel="stylesheet" media="all" href="./assets/application-f82ab2dfef6aa5b0589d092d8949fc1e6126d774e74d5a024c1407a7082732f6.css"/>
<script src="./assets/application-0df5442d7ea56c8d2a38022448c2c9b57397f561885306bbdfff8db7962547c3.js"></script>
</head>
<body>
<div id="ember-app"></div>
</body>
</html>
I then copy the index.html and the assets into a phonegap app directory. When I use the phonegap cli to build the app and launch it on on emulator it comes up with "Application Error - The connection to the server was unsuccessful. (file:///android_asset/www/index.html)". I have tried the various solutions in this post :Application Error - The connection to the server was unsuccessful. (file:///android_asset/www/index.html)
but none resolved my problem. When I open the index.html in a browser I get Uncaught UnrecognizedURLError: /home/paul/Documents/testapp/www/index.html which is coming from somewhere within the ember.js file but I assume this is only because it was loaded from the file system rather than severed from a host.
I have looked into the phonegap-rails gem too, but it looks like the commands it expects to run in phonegap are from an older version and no longer work.
I am not really sure where to go from here, and maybe its just not a good idea to try and do this from rails?
UPDATE:
I gave up on trying to get this to work. I have instead gone with the ember-cli-cordova option (https://github.com/poetic/ember-cli-cordova). Which had a few minor stumbling blocks that were all easily solved and now I am up and running....
If you change the locationType in your environment.js file to 'hash', rather than 'auto', you will solve this issue.
The issue is that phonegap access your app at a url such as file:///android_assets/www/index.html
ember tries to resolve the index.html as a route when the locationType is set to auto.

Resources