base url 托管不会触发云功能
base url hosting doesn't trigger cloud functions
Base url not triggered hosting
我和上面的 link 有同样的问题。
他们提供的解决方案似乎有点奇怪删除 index.html 每次我尝试 build/deploy 我的应用程序也没有工作因为我的 angular 应用程序给出了一个错误 'failed to lookup index'在浏览器目录中。
我试过为“/”添加一条路线
我还为源正则表达式尝试了单 * 和双 **。
"rewrites": [
{
"source": "/",
"function": "ssr_h"
},
{
"source": "**",
"function": "ssr_h"
}
]
并且还试图定义相同的基本路线server.ts。
因为有人告诉我在正则表达式中
** != ''
这是我的全部 server.ts
同样在 server.ts 中尝试了单 * 和双 ** 作为正则表达式中的源。
import 'zone.js/dist/zone-node';
import { ngExpressEngine } from '@nguniversal/express-engine';
import { join } from 'path';
import { AppServerModule } from './src/main.server';
import { APP_BASE_HREF } from '@angular/common';
import { existsSync } from 'fs';
import * as express from 'express';
(global as any).WebSocket = require('ws');
(global as any).XMLHttpRequest = require('xhr2');
const compression = require('compression');
// The Express app is exported so that it can be used by serverless Functions.
// export const app = (): express.Express => {
function server(): express.Express {
const server = express();
const distFolder = join(process.cwd(), 'dist/app/browser');
const indexHtml = existsSync(join(distFolder, 'index.html')) ? 'index.html' : 'index';
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
server.engine('html', ngExpressEngine({
bootstrap: AppServerModule,
}));
server.set('view engine', 'html');
server.set('views', distFolder);
// Example Express Rest API endpoints
// server.get('/api/**', (req, res) => { });
// Serve static files from /browser
server.get('*.*', express.static(distFolder, {
maxAge: '1m'
}));
// All regular routes use the Universal engine
server.get('/', (req, res) => {
res.render(indexHtml, { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }] });
});
server.get('**', (req, res) => {
res.render(indexHtml, { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }] });
});
return server;
}
export const app = server();
app.use(compression());
export * from './src/main.server';
我使用的是 angular 10.
的最新版本
"@angular/cli": "~10.2.3",
"@angular/compiler": "~10.2.5",
"@angular/compiler-cli": "~10.2.5",
"@angular/language-service": "~10.2.5",
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.6.0",
"firebase-functions-test": "^0.2.2",
"firebase-tools": "^8.20.0",
"@nguniversal/express-engine": "^10.1.0",
这个 post 和这个 github 问题是同一个问题,因为我让其他每条路线都正常工作。
我不喜欢我想出的解决方案,但我发现这个教程对我有帮助
angular universal tutorial
因为我的代码已经准备好了,所以我只需要做一些小的改动。
我在 public 指向我的“dist//app//browser”之前更改了它。
将第一个重定向添加到 index2.html,如下面的代码所示。
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source" : "**/*.@(css|js)",
"destination": "/index2.html"
},
{
"source": "**",
"function": "ssr"
}
]
}
}
其他步骤是将其添加到我的部署脚本并将 public 添加到我的 git 忽略
cp -a functions/dist/browser/. public/
mv public/index.html public/index2.html
我和上面的 link 有同样的问题。 他们提供的解决方案似乎有点奇怪删除 index.html 每次我尝试 build/deploy 我的应用程序也没有工作因为我的 angular 应用程序给出了一个错误 'failed to lookup index'在浏览器目录中。 我试过为“/”添加一条路线 我还为源正则表达式尝试了单 * 和双 **。
"rewrites": [
{
"source": "/",
"function": "ssr_h"
},
{
"source": "**",
"function": "ssr_h"
}
]
并且还试图定义相同的基本路线server.ts。 因为有人告诉我在正则表达式中
** != ''
这是我的全部 server.ts 同样在 server.ts 中尝试了单 * 和双 ** 作为正则表达式中的源。
import 'zone.js/dist/zone-node';
import { ngExpressEngine } from '@nguniversal/express-engine';
import { join } from 'path';
import { AppServerModule } from './src/main.server';
import { APP_BASE_HREF } from '@angular/common';
import { existsSync } from 'fs';
import * as express from 'express';
(global as any).WebSocket = require('ws');
(global as any).XMLHttpRequest = require('xhr2');
const compression = require('compression');
// The Express app is exported so that it can be used by serverless Functions.
// export const app = (): express.Express => {
function server(): express.Express {
const server = express();
const distFolder = join(process.cwd(), 'dist/app/browser');
const indexHtml = existsSync(join(distFolder, 'index.html')) ? 'index.html' : 'index';
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
server.engine('html', ngExpressEngine({
bootstrap: AppServerModule,
}));
server.set('view engine', 'html');
server.set('views', distFolder);
// Example Express Rest API endpoints
// server.get('/api/**', (req, res) => { });
// Serve static files from /browser
server.get('*.*', express.static(distFolder, {
maxAge: '1m'
}));
// All regular routes use the Universal engine
server.get('/', (req, res) => {
res.render(indexHtml, { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }] });
});
server.get('**', (req, res) => {
res.render(indexHtml, { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }] });
});
return server;
}
export const app = server();
app.use(compression());
export * from './src/main.server';
我使用的是 angular 10.
的最新版本"@angular/cli": "~10.2.3",
"@angular/compiler": "~10.2.5",
"@angular/compiler-cli": "~10.2.5",
"@angular/language-service": "~10.2.5",
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.6.0",
"firebase-functions-test": "^0.2.2",
"firebase-tools": "^8.20.0",
"@nguniversal/express-engine": "^10.1.0",
这个 post 和这个 github 问题是同一个问题,因为我让其他每条路线都正常工作。
我不喜欢我想出的解决方案,但我发现这个教程对我有帮助 angular universal tutorial
因为我的代码已经准备好了,所以我只需要做一些小的改动。 我在 public 指向我的“dist//app//browser”之前更改了它。 将第一个重定向添加到 index2.html,如下面的代码所示。
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source" : "**/*.@(css|js)",
"destination": "/index2.html"
},
{
"source": "**",
"function": "ssr"
}
]
}
}
其他步骤是将其添加到我的部署脚本并将 public 添加到我的 git 忽略
cp -a functions/dist/browser/. public/
mv public/index.html public/index2.html