Ionic SSR只渲染/ url,只有当我重新加载主页时(Angular 16,Lazy Loading,Pm2)

guykilcj  于 12个月前  发布在  Ionic
关注(0)|答案(1)|浏览(147)

当我在本地启动我的Angular ionic应用程序并刷新页面(所有页面)时,我会看到这些控制台日志。
但是,当我在生产环境中将其部署到PM2上时,我的控制台日志只出现在主页上。
我想动态设置OG Meta标签为Facebook的内部网页以及。
localhost enter image description here
prod enter image description here下面是来自server.ts文件的代码片段

const proxyConfig = environment.production ?
  require('./proxy.conf-prod.json') :
  require('./proxy.conf-dev.json');
console.log(proxyConfig)

export function app(): express.Express {
  const app = express();
  const distFolder = join(process.cwd(), 'dist/monapp/browser');
  const index = existsSync(join(distFolder, 'index.original.html')) ? 'index.original.html' : 'index';

  app.engine('html', ngExpressEngine({
    bootstrap: AppServerModule,
  }));
  const staticFolder = join(process.cwd(), 'dist/monapp/browser/assets');
  app.use('/usr/share/nginx/html/dist/monapp/browser/assets', express.static(staticFolder, {
    maxAge: '1y'
  }));
  const distFolderCustom = environment.production ? "/usr/share/nginx/html/dist/monapp/browser" : distFolder
  app.set('view engine', 'html');
  app.set('views', distFolderCustom);

  const apiProxy = createProxyMiddleware(proxyConfig['/api']);

  app.use('/api', apiProxy);

  app.get('*.*', express.static(distFolder, {
    maxAge: '1y'
  }));

  app.get('*', (req, res) => {
    console.log('SSR requested for URL:', req.originalUrl);

    res.render(index,
      {req, providers: [{provide: APP_BASE_HREF, useValue: req.baseUrl}]},
      async (err, html) => {
        if (html) {
          const resCheck = await checkAndAddTags(html, req.originalUrl).then();
          res.send(resCheck);
        } else {
          res.send(html);
        }
      });
  });
  return app;
}

字符串
“我想在内部页面时查看控制台日志并刷新,是关于根据页面使用setMetadata设置checkAndAddTags的。”

cpjpxq1n

cpjpxq1n1#

经过一整天的研究,我刚刚意识到我的nginx conf的问题
好的会议是

location / {
        proxy_pass http://127.0.0.1:4000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

字符串

location / {
try_files $uri $uri/ /index.html;

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto https;
        proxy_redirect off;

        # Universal rendering configuration
        proxy_pass http://127.0.0.1:4000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_cache_bypass $http_upgrade;
}

相关问题