Я не могу получить доступ к файлам cookie браузера с SSR на производственном сервере Firebase
Вот фрагмент кода:
const Announce = ({ additionalHeaders, err, slug, announceRaw }) => {
console.log(additionalHeaders)
if(err) return <Errors err=err/>
return (
<>
//component content
</>
)
}
export async function getServerSideProps (ctx) {
const { slug } = ctx.query;
const additionalHeaders = { Cookie: ctx.req.headers['cookie'] };
try {
const data = await AnnounceService.getAnnounceBySlugSSR(slug, additionalHeaders);
return {
props: {
additionalHeaders,
data
},
};
} catch (err) {
return {
props: {
additionalHeaders
err
},
};
}
}
Здесь я вызываю свой маршрут API на стороне сервера, который возвращает json данные, если предоставляется token cook ie, иначе код состояния 403.
Он отлично работает во время локальной разработки => Предоставляются дополнительные заголовки
Я получаю свой API прямо с запрос браузера или почтальон, и все также отлично работает
Но я не могу получить заголовок cookie на производственном сервере firebase
PS: Я использую CORS с credentials : include
, но это определенно не проблема cors
Вывод localhost console.log
{
"additionalHeaders": {
"Cookie": "_ga=GA1.3.90XXXXXXXXXXX; _gid=GA1.3.211XXXXXXXX; _gat=1; token=MY_AUTH_TOKEN_PASSED_TO_API, someOthersCookies : ...."
}
}
Вывод production console.log
{
"additionalHeaders": {}
}
PS2: Я пытался развернуть с помощью Vercel (Zeit) и он работает как шарм в производственном режиме
Если не удается решить эту проблему с помощью firebase, мне придется подписаться на корпоративный план Vercel
Кто-нибудь знает?
Спасибо
файлы конфигурации
удовольствие ctions. js
'use strict';
const admin = require('firebase-admin');
const functions = require('firebase-functions');
const next = require('next');
const runtimeOpts = {
timeoutSeconds: 300,
memory: '1GB',
};
admin.initializeApp();
const dev = process.env.NODE_ENV !== 'production';
const app = next({
dev,
conf: {
distDir: 'dist',
},
});
const handle = app.getRequestHandler();
exports.next = functions
.runWith(runtimeOpts)
.https
.onRequest((req, res) => {
try {
app.prepare().then(() => handle(req, res));
} catch (err) {
return err;
}
});
firebase. json
{
"functions": {
"source": ".",
"ignore": [
"node_modules",
".git",
".gitignore",
".nyc_output",
"firebase-debug.log"
]
},
"hosting": {
"public": "public",
"rewrites": [
{
"source": "**/**",
"function": "next"
}
],
"ignore": [
".firebase/**",
"firebase.json",
".firebaserc",
"**/node_modules/**",
"**/.*",
"**"
]
}
}
next.config. js
const withPlugins = require('next-compose-plugins')
const withImages = require('next-images')
const path = require('path')
require('dotenv').config()
const nextConfig = {
distDir: 'dist',
env: {},
webpack: (config) => {
config.resolve.mainFields = ['main', 'browser', 'module']
return config
},
}
module.exports = nextConfig
package. json
{
"main": "functions.js",
"scripts": {
"clean": "rimraf dist",
"dev": "yarn clean && next",
"start": "next start",
"build": "rimraf dist && next build",
"deploy": "yarn build && yarn push",
"ignore-engine": "yarn config set ignore-engines true",
"push": "yarn ignore-engine && firebase deploy --only functions,hosting --debug"
},
"engines": {
"node": "10" // required relating to firebase functions documentation (bypassed with ignore-engine command)
},
"dependencies": {
"next": "9.3.5",
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.6.0",
.....
}
Информация о системе
- ОС: Windows
- Версия узла: 14.3.0