Gulp browser sync not for json files

I have a problem when I cannot serve files jsonfrom my subfolders. Below is the code:

var browserSync = require('browser-sync').create();

// Static server
gulp.task('connect', function() {
    browserSync.init({
      server: {
        baseDir: "app/"
      }
    });
});

All my files staticand angularjsfound within the application folder. When I go to http://localhost:3000, the page loads, but the corresponding json file inside app/data/myfile.jsondoes not load.

I get the following error in my console:

POST http: // localhost: 3000 / data / json / myfile.json 404 (not found)

The strange thing is, when I try to load the path in my browser, the json file is loaded.

+4
source share
1 answer

https://www.browsersync.io/docs/options/#option-serveStatic FAIL.

const ASSET_EXTENSION_REGEX = new RegExp(`\\b(?!\\?)\\.(${config.assetExtensions.join('|')})\\b(?!\\.)`, 'i');
     const DEFAULT_FILE = 'index.html';
...
        server: {
          baseDir: './build',
          middleware: function(req, res, next) {
            let fileHref = url.parse(req.url).href;

            if ( !ASSET_EXTENSION_REGEX.test(fileHref) ) {
              req.url = '/' + DEFAULT_FILE;
            }

            return next();
          }
        }
     ...

config = {assetExtensions: [     'JS',     'CSS',     'PNG',     'JPE? ',     'GIF',     'SVG',      "",      "",      "",     'TTF',     'JSON',     "Woff2? ]}

0

Source: https://habr.com/ru/post/1624581/


All Articles