我有一个基于nodejs的firebase函数,我使用express app在单个firebase函数中创建了一个复杂的api,如下所示:
import * as functions from 'firebase-functions';
const express = require('express');
var cors = require('cors')
const app = express();
app.use(cors({ origin: true }))
app.get('/:appId/posts/:id', (request:any, response:any) => {
var origin = request.get('Origin'); // null
var origin2 = request.header('Origin'); // null
var origin3 = request.get('origin'); // null
var origin4 = request.header('origin'); // null
var origin5 = request.get('referer'); // null
var origin6 = request.get('host'); // null
});
exports.api = functions.https.onRequest(app);
我需要获取请求的来源,业务逻辑取决于它。
所以,问题是:如何获得请求来源?
答案 0 :(得分:0)
尝试一下:
io.on('connection', function (socket) {
let host = socket.handshake.headers.origin
...