Tag Archive for: HTTP

Forcing the domain to serve securely using HTTPS (for any site)

Is your WordPress site shown as No Secure Connection? Solve this easily forcing any http request to be rewritten using https. Just copy and paste the code below into your .htaccess file exactly as shown.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Header always set Content-Security-Policy: upgrade-insecure-requests

Simple local development environment for web apps

  1. Open your app working directory
    • There you should have at least index.html
  2. Launch http-server in your terminal
    • If you haven’t installed it yet: npm install http-server -g
  3. Launch chromium-browser --disable-web-security --user-data-dir=/tmp/something in your terminal to allow all origins (temporary ignore  CORS mechanism )
    • Make sure you don’t have other instances open: pkill -f chromium
  4. Type in the address bar one of the address from your http-server info to access to your app

Note: Use Chromium without security just with your own code for testing and development, do not browse with it and beware about using third-party software in your code.

Post JSON data to an URL

The easiest way to do a POST in JavaScript: using fetch.

Get JSON data from an URL

AJAX request using ES6 Promises with fetch and XMLHttpRequest. Notice that the url needs https because we request from https and the server should allow all origins (Access-Control-Allow-Origin: *)

Fetch is simpler and cleaner, it avoid callback hell and having to remember the complex API of XMLHttpRequest.