Suddenly I'm getting this error message, strange to me since I haven't been touching the map part :

Failed to load resource: the server responded with a status of 403 ()

Searching for a clue I found this outdated info:

https://ninio.ninarski.com/2014/06/18/leaflet-tiles-failed-to-load-resource-the-server-responded-with-a-status-of-403-forbidden/

But I'm aleady using openstreetmap as tiles provider :

<TileLayer url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" />

Other info:

"@types/leaflet": "^1.7.9",
"leaflet": "^1.7.1",
"react": "18",
"react-dom": "18",
"react-leaflet": "4.0.0-beta.0",
"react-leaflet-fullscreen": "^2.0.2",
"react-leaflet-textpath": "^2.1.1",
node : v16.13.0
O.S.: Ubuntu 20.04 Desktop

This is the complete related code:

import * as React from 'react'; import * as leaflet from 'leaflet' import { MapContainer, Marker, Popup, TileLayer } from "react-leaflet"; import "./leaflet.css"

const position = [51.505, -0.09];

export default function Mapping(props) {
return (
    <MapContainer center={position} zoom={13}>
      <TileLayer
        attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
        url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
      />
      <Marker position={position}>
        <Popup>
          A pretty CSS3 popup. <br /> Easily customizable.
        </Popup>
      </Marker>
    </MapContainer>
  );

}

A part of leaflet.css file is:

/* required styles */

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
        position: absolute;
        left: 0;
        top: 0;
        }
.leaflet-container {
        /*overflow: hidden;*/
        width: 100%;
        height: 100%;
        }
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
        -webkit-user-select: none;
           -moz-user-select: none;
                user-select: none;
          -webkit-user-drag: none;
        }
/* Prevents IE11 from highlighting tiles in blue */
.leaflet-tile::selection {
        background: transparent;
}
/* Safari renders non-retina tile on retina better with this, but Chrome is worse */
.leaflet-safari .leaflet-tile {
        image-rendering: -webkit-optimize-contrast;
        }
/* hack that prevents hw layers "stretching" when loading new tiles */
.leaflet-safari .leaflet-tile-container {
        width: 100%;
        height: 100%;
        -webkit-transform-origin: 0 0;
        }
.leaflet-marker-icon,
.leaflet-marker-shadow {
        display: block;
        }
/* .leaflet-container svg: reset svg max-width decleration shipped in Joomla! (joomla.org) 3.x */
/* .leaflet-container img: map is broken in FF if you have max-width: 100% on tiles */
.leaflet-container .leaflet-overlay-pane svg,
.leaflet-container .leaflet-marker-pane img,
.leaflet-container .leaflet-shadow-pane img,
.leaflet-container .leaflet-tile-pane img,
.leaflet-container img.leaflet-image-layer,
.leaflet-container .leaflet-tile {
        max-width: none !important;
        max-height: none !important;
        }

.leaflet-container.leaflet-touch-zoom {
        -ms-touch-action: pan-x pan-y;
        touch-action: pan-x pan-y;
        }
.leaflet-container.leaflet-touch-drag {
        -ms-touch-action: pinch-zoom;
        /* Fallback for FF which doesn't support pinch-zoom */
        touch-action: none;
        touch-action: pinch-zoom;
}
.leaflet-container.leaflet-touch-drag.leaflet-touch-zoom {
        -ms-touch-action: none;
        touch-action: none;
}
.leaflet-container {
        -webkit-tap-highlight-color: transparent;
}
.leaflet-container a {
        -webkit-tap-highlight-color: rgba(51, 181, 229, 0.4);
}
.leaflet-tile {
        filter: inherit;
        visibility: hidden;
        }
.leaflet-tile-loaded {
        visibility: inherit;
        }
.leaflet-zoom-box {
        width: 0;
        height: 0;
        -moz-box-sizing: border-box;
             box-sizing: border-box;
        z-index: 800;
        }
/* workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=888319 */
.leaflet-overlay-pane svg {
        -moz-user-select: none;
        }

.leaflet-pane         { z-index: 400; }

.leaflet-tile-pane    { z-index: 200; }
.leaflet-overlay-pane { z-index: 400; }
.leaflet-shadow-pane  { z-index: 500; }
.leaflet-marker-pane  { z-index: 600; }
.leaflet-tooltip-pane   { z-index: 650; }
.leaflet-popup-pane   { z-index: 700; }

.leaflet-map-pane canvas { z-index: 100; }
.leaflet-map-pane svg    { z-index: 200; }

.leaflet-vml-shape {
        width: 1px;
        height: 1px;
        }
.lvml {
        behavior: url(#default#VML);
        display: inline-block;
        position: absolute;
        }
/* control positioning */

.leaflet-control {
        position: relative;
        z-index: 800;
        pointer-events: visiblePainted; /* IE 9-10 doesn't have auto */
        pointer-events: auto;
        }
.leaflet-top,
.leaflet-bottom {
        position: absolute;
        z-index: 1000;
        pointer-events: none;
        }
.leaflet-top {
        top: 0;
        }
.leaflet-right {
        right: 0;
        }
.leaflet-bottom {
        bottom: 0;
        }
.leaflet-left {
        left: 0;
        }
.leaflet-control {
        float: left;
        clear: both;
        }
.leaflet-right .leaflet-control {
        float: right;
        }
.leaflet-top .leaflet-control {
        margin-top: 10px;
        }
.leaflet-bottom .leaflet-control {
        margin-bottom: 10px;
        }
.leaflet-left .leaflet-control {
        margin-left: 10px;
        }
.leaflet-right .leaflet-control {
        margin-right: 10px;
        }


/* zoom and fade animations */

.leaflet-fade-anim .leaflet-tile {
        will-change: opacity;
        }
.leaflet-fade-anim .leaflet-popup {
        opacity: 0;
        -webkit-transition: opacity 0.2s linear;
           -moz-transition: opacity 0.2s linear;
                transition: opacity 0.2s linear;
        }
.leaflet-fade-anim .leaflet-map-pane .leaflet-popup {
        opacity: 1;
        }
.leaflet-zoom-animated {
        -webkit-transform-origin: 0 0;
            -ms-transform-origin: 0 0;
                transform-origin: 0 0;
        }
.leaflet-zoom-anim .leaflet-zoom-animated {
        will-change: transform;
        }
.leaflet-zoom-anim .leaflet-zoom-animated {
        -webkit-transition: -webkit-transform 0.25s cubic-bezier(0,0,0.25,1);
           -moz-transition:    -moz-transform 0.25s cubic-bezier(0,0,0.25,1);
                transition:         transform 0.25s cubic-bezier(0,0,0.25,1);
        }
.leaflet-zoom-anim .leaflet-tile,
.leaflet-pan-anim .leaflet-tile {
        -webkit-transition: none;
           -moz-transition: none;
                transition: none;
        }

.leaflet-zoom-anim .leaflet-zoom-hide {
        visibility: hidden;
        }


/* cursors */

.leaflet-interactive {
        cursor: pointer;
        }
.leaflet-grab {
        cursor: -webkit-grab;
        cursor:    -moz-grab;
        cursor:         grab;
        }
.leaflet-crosshair,
.leaflet-crosshair .leaflet-interactive {
        cursor: crosshair;
        }
.leaflet-popup-pane,
.leaflet-control {
        cursor: auto;
        }
.leaflet-dragging .leaflet-grab,
.leaflet-dragging .leaflet-grab .leaflet-interactive,
.leaflet-dragging .leaflet-marker-draggable {
        cursor: move;
        cursor: -webkit-grabbing;
        cursor:    -moz-grabbing;
        cursor:         grabbing;
        }

/* marker & overlays interactivity */
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-image-layer,
.leaflet-pane > svg path,
.leaflet-tile-container {
        pointer-events: none;
        }

.leaflet-marker-icon.leaflet-interactive,
.leaflet-image-layer.leaflet-interactive,
.leaflet-pane > svg path.leaflet-interactive,
svg.leaflet-image-layer.leaflet-interactive path {
        pointer-events: visiblePainted; /* IE 9-10 doesn't have auto */
        pointer-events: auto;
        }
/* visual tweaks */

.leaflet-container {
        background: #ddd;
        outline: 0;
        }
.leaflet-container a {
        color: #0078A8;
        }
.leaflet-container a.leaflet-active {
        outline: 2px solid orange;
        }
.leaflet-zoom-box {
        border: 2px dotted #38f;
        background: rgba(255,255,255,0.5);
        }


/* general typography */
.leaflet-container {
        font: 12px/1.5 "Helvetica Neue", Arial, Helvetica, sans-serif;
        }


/* general toolbar styles */

.leaflet-bar {
        box-shadow: 0 1px 5px rgba(0,0,0,0.65);
        border-radius: 4px;
        }
.leaflet-bar a,
.leaflet-bar a:hover {
        background-color: #fff;
        border-bottom: 1px solid #ccc;
        width: 26px;
        height: 26px;
        line-height: 26px;
        display: block;
        text-align: center;
        text-decoration: none;
        color: black;
        }
.leaflet-bar a,
.leaflet-control-layers-toggle {
        background-position: 50% 50%;
        background-repeat: no-repeat;
        display: block;
        }
.leaflet-bar a:hover {
        background-color: #f4f4f4;
        }
.leaflet-bar a:first-child {
        border-top-left-radius: 4px;
        border-top-right-radius: 4px;
        }
.leaflet-bar a:last-child {
        border-bottom-left-radius: 4px;
        border-bottom-right-radius: 4px;
        border-bottom: none;
        }
.leaflet-bar a.leaflet-disabled {
        cursor: default;
        background-color: #f4f4f4;
        color: #bbb;
        }
.leaflet-touch .leaflet-bar a {
        width: 30px;
        height: 30px;
        line-height: 30px;
        }
.leaflet-touch .leaflet-bar a:first-child {
        border-top-left-radius: 2px;
        border-top-right-radius: 2px;
        }
.leaflet-touch .leaflet-bar a:last-child {
        border-bottom-left-radius: 2px;
        border-bottom-right-radius: 2px;
        }

/* zoom control */

.leaflet-control-zoom-in,
.leaflet-control-zoom-out {
        font: bold 18px 'Lucida Console', Monaco, monospace;
        text-indent: 1px;
        }

.leaflet-touch .leaflet-control-zoom-in, .leaflet-touch .leaflet-control-zoom-out  {
        font-size: 22px;
        }

This is the html file:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="original-trial" content=AhRSNW+2zbXlDahhAcj194oqlgDxj3TqG4sYwhsUdqldtNbZagboEjqIJZuUvBsIjtij4VSW0YvP5tGSpVgu6wgAAABzeyJvcmlnaW4iOiJodHRwczovL2dnYy53b3JsZDo0NDMiLCJmZWF0dXJlIjoiVW5yZXN0cmljdGVkU2hhcmVkQXJyYXlCdWZmZXIiLCJleHBpcnkiOjE2MzM0Nzg>
  </head>
  <body>
    <div id="app_G"></div>
    <div class='viewer' id='viewerG' title="Web Page" width= "480" height="480">
    <div id="map"></div>
    <script> const global = globalThis; </script>
    <script></script>
    <style>
      .leaflet-container {
        height: 800px;
        width: 800px;
       }
     </style>

  </body>
</html>

What I get is the grey map :

enter image description here

with these error messages:

Failed to load resource: the server responded with a status of 403 ()

Eliminating this line:

    <meta http-equiv="original-trial" content=AhRSNW+2zbXlDahhAcj194oqlgDxj3TqG4sYwhsUdqldtNbZagboEjqIJZuUvBsIjtij4VSW0YvP5tGSpVgu6wgAAABzeyJvcmlnaW4iOiJodHRwczovL2dnYy53b3JsZDo0NDMiLCJmZWF0dXJlIjoiVW5yZXN0cmljdGVkU2hhcmVkQXJyYXlCdWZmZXIiLCJleHBpcnkiOjE2MzM0Nzg>

from the html page produces this effect :

enter image description here

Where we can see a sketch of the tiles outline, but still do not see the map and get the error message : Failed to load resource: the server responded with a status of 404 So, I do not understand if this is the right direction to solve the issue

If I add to the html file: this line :

<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"   integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA=="   crossorigin=""/>

and thus, the resulting html page is :

    <!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">


  </head>
  <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"   integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA=="   crossorigin=""/>
  <body>
    <div id="app_G"></div>
    <div class='viewer' id='viewerG' title="Web Page" width= "480" height="480">
    <div id="map"></div>
    <script> const global = globalThis; </script>
    <script></script>
    <style>
      .leaflet-container {
        height: 800px;
        width: 100%;
       }
     </style>

  </body>
</html>

I still get a grey map :

enter image description here

with the already mentioned error message Failed to load resource: the server responded with a status of 404 (Not Found)

Based on the info here : https://operations.osmfoundation.org/policies/tiles/ the following are the requirements for the openstreetmap tiles usage:

Requirements

    Heavy use (e.g. distributing an app that uses tiles from openstreetmap.org) is forbidden without prior permission from the [Operations Working Group](https://wiki.osmfoundation.org/wiki/Operations_Working_Group). See below for alternatives.
    Clearly display [license](https://wiki.openstreetmap.org/wiki/License) attribution.
    Do not actively or passively encourage copyright infringement.
    Calls to /cgi-bin/export may only be triggered by direct end-user action. (For example: “click here to export”.) The export call is an expensive (CPU+RAM) function to run and will frequently reject when server is under high load.
    Recommended: Do not hardcode any URL at tile.openstreetmap.org as doing so will limit your ability to react quickly if the service is disrupted or blocked.
    Recommended: add a link to https://www.openstreetmap.org/fixthemap to allow your users to report and fix problems in our data.

Technical Usage Requirements

    Valid [HTTP User-Agent](http://en.wikipedia.org/wiki/en:User_agent) identifying application. Faking another app’s User-Agent WILL get you blocked.
    If known, a valid [HTTP Referer](http://en.wikipedia.org/wiki/en:HTTP_Referer).
    DO NOT send no-cache headers. (“Cache-Control: no-cache”, “Pragma: no-cache” etc.)
    Cache Tile downloads locally according to HTTP Expiry Header, alternatively a minimum of 7 days.
    Maximum of 2 download threads. (Unmodified web browsers’ download thread limits are acceptable.)

Note: modern web browsers in standard configuration generally pass all the above technical requirements.

As far as I understand, I have been respecting all of them

This is the complete webpack.config.js file:

const path = require('path'); const cwd = process.cwd(); const HtmlWebpackPlugin = require('html-webpack-plugin'); const CopyPlugin = require("copy-webpack-plugin"); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const webpack = require('webpack');

function srcPaths(src) {
  return path.join(__dirname, src);
}

const isEnvProduction = process.env.NODE_ENV === 'production';
const isEnvDevelopment = process.env.NODE_ENV === 'development';

  // main process
var main_config = {
    mode: isEnvProduction ? 'production' : 'development',
    entry: './src/main/main.ts',
    target: 'electron-main',
    resolve: {
      extensions: ['.jsx', '.js', 'ts'],
    },
    externals: [
      {
        'utf-8-validate': 'commonjs utf-8-validate',
        bufferutil: 'commonjs bufferutil',
      },
    ],
    module: {
      rules: [
        {
          test: /\.ts$/,
          include: /src/,
          use: [{ loader: 'ts-loader' }]
        },
        {
          test: /\.(sass|less|css)$/i,
          use: [
            {
              loader: 'style-loader'
            },
            {
              loader: 'css-loader'
            },
            {
              loader: 'less-loader',
            },
          ],
        },
        {
          test: /\.s?css$/,
          use: [
            {
              loader: MiniCssExtractPlugin.loader,
              options: {
                sourceMap: true
              }
            },
            {
              loader: 'css-loader',
              options: {
                sourceMap: true
              }
            },
            {
              loader: 'sass-loader',
              options: {
                sourceMap: true
              }
            }
          ]
        },
        {
          test: /\.(png|jpe?g|svg|gif)$/i,
          use: [
            {
              loader: "file-loader",
              options: {
                name: "[path]/[name].[ext]",
              },
            },
          ],
        },
        {
          test: /\.geojson$/,
           use: [
             {
               loader: "json-loader",
             }
          ],
        }
      ]
    },
    output: {
      path: __dirname + '/dist',
      filename: 'main.js'
    },
    node: {
      __dirname: false,
      __filename: false
    },
};
  // renderer process
var renderer_config =  {
    mode: isEnvProduction ? 'production' : 'development',
    entry: {
      app: ['./src/app/index.tsx', 'react-app-polyfill/stable'],
      style: [
        './src/app/styles/index.css',
        path.resolve(__dirname, 'node_modules/leaflet/dist/leaflet.css')
      ]
    },
    //target: 'electron-renderer',
    //target: 'web',
    target: ['web', 'es5'],
    resolve: {
      extensions: ['.jsx', '.js', '.tsx', '.ts'],
    },
    output: {
      path: __dirname + '/dist/',
        //filename: 'renderer.js'
      filename: '[name].js',
    },
    externals: [
      {
        'utf-8-validate': 'commonjs utf-8-validate',
        bufferutil: 'commonjs bufferutil',
      },
    ],
    module: {
      rules: [
        {
          test: /\.(js|ts)x?$/,
          exclude: /node_modules/,
          use: {
            loader: 'babel-loader',
          },
        },
        {
          // css files
          test: /\.css$/i,
          use: [
            {
              loader: 'style-loader'
            },
            {
              loader: 'css-loader'
            },
          ],
        },
        {
          test: /\.(png|jpe?g|svg|gif)$/i,
          use: [
            {
              loader: "file-loader",
              options: {
                name: "[path]/[name].[ext]",
              },
            },
          ],
        },
        {
          // Font files
          test: /\.(woff|woff2|ttf|otf)$/,
          loader: 'file-loader',
          options: {
            name: '[hash].[ext]',
            outputPath: 'dist/assets/css/'
          }
        },
      ],
    },
    node: {
      __dirname: false,
      __filename: false
    },
    plugins: [
      new HtmlWebpackPlugin({
        filename: 'index.html',
        template: './src/app/index.html',
        inject:'body',
        chunks: ['app'],
      }),
      new MiniCssExtractPlugin({
        filename: '[name].css',
        chunkFilename: '[id].css',
        linkType: 'text/css',
      }),
      new CopyPlugin({
        patterns: [
          {
            from: path.resolve(__dirname, "./src/assets/css"),
            to: path.resolve(__dirname, "./dist/assets/css")
          },
        ],
        options: {
          concurrency: 100,
        },
      }),
    ]
}

module.exports = [
  main_config,
  renderer_config,
];

Update 1)

Correcting the typo in index.html : original-trial to origin-trial doesn't unfortunately resolve the problem:

I still get, for example: Failed to load resource: the server responded with a status of 403 () 2724.png:1

enter image description here

Where should I focus my attention in order to solve the problem?

0

There are 0 best solutions below