Webentwicklung

So beheben Sie den CORS-Fehler in Socket IO NodeJS

[ad_1]

So beheben Sie den CORS-Fehler in Socket IO NodeJS

In diesem kurzen Tutorial zeige ich Ihnen, wie Sie CORS-Fehler im Socket-IO in NodeJS beheben können.

Zunächst müssen Sie die Socket-IO-Importanweisung wie folgt verwenden:

const socketIO = require("socket.io")(http, {
	cors: {
		origin: "*"
	}
})

Anschließend können Sie mit Ihrer Express-App-Instanz die folgenden Header festlegen.

// Add headers before the routes are defined
app.use(function (req, res, next) {

    // Website you wish to allow to connect
    res.setHeader("Access-Control-Allow-Origin", "*")

    // Request methods you wish to allow
    res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, PATCH, DELETE")

    // Request headers you wish to allow
    res.setHeader("Access-Control-Allow-Headers", "X-Requested-With,content-type,Authorization")

    // Set to true if you need the website to include cookies in the requests sent
    // to the API (e.g. in case you use sessions)
    res.setHeader("Access-Control-Allow-Credentials", true)

    // Pass to next layer of middleware
    next()
})


[ad_2]

Tags

Related Articles

Close
Immediate Momentumxnxx story sex meyzo.me haryana sex نيك بنت جامدة porn-arab.net احلى قصص نيك نيك ممثله ounoun.com صور مص اللسان shruti hasan porn desixxxv.net indiaxx hindi movie xxx video flyporntube.net lokl sex www.xnxx.xom russianporntrends.com local assamese sex video mide-689 freejavstreaming.net 無修正 温泉 تحميل سكس مترجم orivive.com فيس بوك سكس carla abellana shows pinoytvpage.com starstruck last batch sexy girls xxx pornia.info hindi hot sexy video download ang probinsyano june 24 2022 full episode advance teleseryeone.com apoy sa langit june 9 2022 artikulo 247 may 19 eteleserye.com umiiwas in english sexa xxx blowjobporntrends.com tamil sex full video tamil padam sex padam tubedessert.mobi www videos9 com india ka sexy video teenporntrends.com pornohut.su