I am trying to deploy "my angular universal" project to firebase hosting via firebase function (SSR). But I am getting an error.
I want to mention that I had configured my routes as was in specs. And on the local server, it works perfectly.
But during the deploying process, I am getting this error.
Http failure during parsing for https://accounts.google.com/ServiceLogin?service=ah&passive=true&continue=https://uc.appengine.google.com/_ah/conflogin%3Fcontinue%3Dhttp://us-central1-projecName.cloudfunctions.net/assets/i18n/en.json SyntaxError: Unexpected token < in JSON at position 1 at JSON.parse (<anonymous>)
this is my translate.interceptor.ts
`import { REQUEST } from '@nguniversal/express-engine/tokens';
import * as express from 'express';
import {
HttpHandler,
HttpInterceptor,
HttpRequest,
} from '@angular/common/http';
import { Inject, Injectable, Injector, PLATFORM_ID } from '@angular/core';
import { isPlatformServer } from '@angular/common';
@Injectable()
export class TranslateInterceptor implements HttpInterceptor {
private readonly DEFAULT_PORT = 4200;
private readonly PORT = process.env.PORT || this.DEFAULT_PORT;
Hi
I am trying to deploy "my angular universal" project to firebase hosting via firebase function (SSR). But I am getting an error. I want to mention that I had configured my routes as was in specs. And on the local server, it works perfectly. But during the deploying process, I am getting this error.
Http failure during parsing for https://accounts.google.com/ServiceLogin?service=ah&passive=true&continue=https://uc.appengine.google.com/_ah/conflogin%3Fcontinue%3Dhttp://us-central1-projecName.cloudfunctions.net/assets/i18n/en.json SyntaxError: Unexpected token < in JSON at position 1 at JSON.parse (<anonymous>)
this is my translate.interceptor.ts`import { REQUEST } from '@nguniversal/express-engine/tokens'; import * as express from 'express'; import { HttpHandler, HttpInterceptor, HttpRequest, } from '@angular/common/http'; import { Inject, Injectable, Injector, PLATFORM_ID } from '@angular/core'; import { isPlatformServer } from '@angular/common';
@Injectable() export class TranslateInterceptor implements HttpInterceptor { private readonly DEFAULT_PORT = 4200; private readonly PORT = process.env.PORT || this.DEFAULT_PORT;
constructor( @Inject(PLATFORM_ID) private platformId: object, private injector: Injector ) {}
intercept(request: HttpRequest, next: HttpHandler) {
if (request.url.includes('assets') && isPlatformServer(this.platformId)) {
const req = this.injector.get(REQUEST);
const url = req.protocol + '://' + req.get('host') + '/' + request.url;
request = request.clone({
url,
});
}
return next.handle(request);
}
}
`
and this is part from server.ts
` function ngApp(req: any, res: any) { res.render(indexHtml, { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }], }); }
server.get('', ngApp); const fs = require('fs'); const configPath = join(distFolder, 'assets/i18n/configi18.json'); const data: any = JSON.parse(fs.readFileSync(configPath, 'utf8')); data.locales.forEach((route) => { server.get(
/${route}
, ngApp); server.get(`/${route}/`, ngApp); });return server;`
And this is my firebase ssr function (I use @angular/fire)
`const functions = require('firebase-functions');
const expressApp = require('./dist/server/main').app();
exports.ssr = functions .region('us-central1') .runWith({"timeoutSeconds":60,"memory":"1GB"}) .https .onRequest(expressApp); `
Everything works well in the local server.
Please can you help someway? Some information. some suggestions.
Thank you in advance