CORS error until glitch site wakes up

No ‘Access-Control-Allow-Origin’ header is present, says service worker console for the first request, and then after a few seconds second request goes fine.

I assume it happens due to glitch site sleeping at the time of the first request.

Is there any way to handle this other than to actually make two time separated requests?

Also, is it not surprising the timeout is not applied and instead it cancels connection straight away?

This is happening because of the loading page we added that is displayed until your project starts. You can avoid that by adding a Content-Type header to your request - then we won’t try to display the welcome page.

Thank you, Tim. So I went to add that header and noticed I already had it, like this:

$.ajaxSetup({async:true, cache:false, timeout:9999,
dataType:‘text’, contentType:‘text/plain’, processData:false});

I then removed both dataType and contentType from the setup and it worked in that it didn’t cancel connection, but timed out after 10 seconds. Second request went fine as before.

I’m now waiting for glitch site to fall asleep and will try again, and maybe it will work, but I thought I should report what wappened so far in any case… second attempt timed out as well. (sends request):

    $.ajaxSetup({async:true, cache:false, timeout:9999, processData:false});
    var appPath= '';
      url:appPath +'/lod', type:'GET',
      error:function(e, f)
        adminInfo.innerText+= 'FAIL@client:'+ f +'\n';
      success:function(r, s, x)
        var d= r.replace(/\n|\r/g, '');
    }); (serves response):

var ex= require('express'), ap= ex();
var wl= ['', ''];

function sh(q,a)
  var o= q.headers.origin;
  if(wl.indexOf(o) < 0) { q.connection.destroy(); return; }  
ap.get('/lod', function(q, a)
  a.sendFile(__dirname + '/db.txt');


After all it seems “processData:false” was the true troublemaker here, took that out too and now it works as desired/expected.

I could perhaps put back “dataType:‘text’, contentType:‘text/plain’”, but why would when it already works as it is.

Thanks again.