Server is in my native community, serving HTTP
(not HTTPS
). It makes use of libraries categorical
, cors
, bodyparser
.
Passing net shopper is on Chrome macOS model 135.0.7049.85
.
Failing net shopper is on Chrome iOS model 135.0.7049.83
.
I’ve confirmed that CORS shouldn’t be the difficulty, and I can see server logs accepting the request and returning response.
I attempted disabling “protected searching” in Chrome settings, no change.
I attempted changing $.ajax
with fetch
, no change.
HTML
JS
async perform f1() {
console.log('earlier than request')
const res_subs = await $.ajax({
methodology: 'POST',
url: '/db',
information: {
endpoint: 'endpoint1',
worth: 'one two',
language: 'abc'
}
})
console.log('after request')
}
JS utilizing fetch
async perform f1() {
console.log('earlier than request')
const res = await fetch(
'/db',
{
methodology: 'POST',
physique: JSON.stringify({
endpoint: 'endpoint1',
worth: 'one two',
language: 'abc'
}),
headers: [
['Content-Type', 'application/json']
]
}
)
if (!res.okay) {
throw new Error(res.statusText)
}
console.log('after request')
}
Output
earlier than request
after request
is rarely printed.
JS
const categorical = require('categorical')
const bodyparser = require('body-parser')
const cors = require('cors')
// cross origin request origins
const origins = [
'http://localhost', 'http://127.0.0.1', // local testing (same device)
'http://', // local testing (different device)
// etc
]
// deal with POST request information with bodyparser
server.use(bodyparser.json())
server.use(bodyparser.urlencoded({
prolonged: false,
restrict: '50mb'
}))
server.use(cors({
origin: perform (origin, callback) {
if (origin != null && origins.indexOf(origin) == -1) {
log.error(`cross origin request failed for ${origin}`)
return callback(new Error('CORS for origin ' + origin + ' shouldn't be allowed entry.'), false)
}
else {
return callback(null, true)
}
}
}))
server.set('port', 80)
/**
*
* @param {string} endpoint
* @param {object} args
* @param {import('categorical').Response} res
*/
perform handle_db(endpoint, args, res) {
// converts request to a database question, returns consequence
log.debug(`res.size=${information.size}`, ctx)
res.json(information)
res.on('end', () => { log.debug('res.end', ctx) })
}
//expose database
server
.route('/db')
.publish(perform (req, res) {
handle_db(
req.physique.endpoint, // db api endpoint
req.physique, // different arguments
res
)
})
Output
db_server.fundamental.79.data: database linked efficiently
...
server.handle_db.97.debug: res.size=13
server.handle_db.99.debug: res.end
Preflight OPTIONS
dealing with affirmation
Beneath is default OPTIONS
preflight response from categorical
server with cors
middleware.
$ curl -X OPTIONS http://localhost/db -i
HTTP/1.1 204 No Content material
X-Powered-By: Categorical
Range: Origin, Entry-Management-Request-Headers
Entry-Management-Enable-Strategies: GET,HEAD,PUT,PATCH,POST,DELETE
Content material-Size: 0
Date: Solar, 13 Apr 2025 02:19:50 GMT
Connection: keep-alive
Maintain-Alive: timeout=5