admin管理员组文章数量:1122846
I'm converting my CSR Angular app to SSR using .NET 6. Now the .NET backend is having trouble serving the files for the frontend. All the files build and are correctly placed in the proper directories. See snippets for setup files below.
angular.json
:
"server": {
"builder": "@angular-devkit/build-angular:server",
"options": {
"outputPath": "dist/my-app/server",
"main": "src/main.server.ts",
"tsConfig": "tsconfig.server.json"
},
"configurations": {
...
}
},
"serve-ssr": {
"builder": "@angular-devkit/build-angular:ssr-dev-server",
"options": {
"host": "localhost",
"port": 44492,
"ssl": true,
"sslCert": "%APPDATA%\\ASP.NET\\https\\%npm_package_name%.pem",
"sslKey": "%APPDATA%\\ASP.NET\\https\\%npm_package_name%.key",
"proxyConfig": "proxy.conf.js"
},
"configurations": {
"development": {
"browserTarget": "my-app:build:development",
"serverTarget": "my-app:server:development"
},
"production": {
"browserTarget": "my-app:build:production",
"serverTarget": "my-app:server:production"
}
},
"defaultConfiguration": "development"
},
tsconfig.server.json
:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./dist/my-app/server",
"target": "es2022",
"module": "es2022",
"moduleResolution": "node",
"types": ["node"],
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
},
"files": [
"src/main.server.ts"
],
"angularCompilerOptions": {
"enableIvy": true
}
}
main.server.ts
:
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/appponent';
import { serverAppConfig } from './app/app.config.server';
const bootstrap = () => bootstrapApplication(AppComponent, serverAppConfig);
export default bootstrap;
server.ts
:
import 'zone.js/node';
import { APP_BASE_HREF } from '@angular/common';
import { CommonEngine } from '@angular/ssr/node';
import * as express from 'express';
import { existsSync } from 'node:fs';
import { join } from 'node:path';
import AppServerModule from './src/main.server';
// Define paths
const distFolder = join(process.cwd(), 'dist', 'my-app', 'browser');
const serverFolder = join(process.cwd(), 'dist', 'my-app', 'server');
const indexHtml = existsSync(join(distFolder, 'index.original.html'))
? join(distFolder, 'index.original.html')
: join(distFolder, 'index.html');
// Initialize CommonEngine for SSR
const commonEngine = new CommonEngine();
export function app(): express.Express {
const server = express();
server.set('view engine', 'html');
server.set('views', distFolder);
//
本文标签:
cHow do I get Angular 19 SSR to work with NET 6Stack Overflow
版权声明:本文标题:c# - How do I get Angular 19 SSR to work with .NET 6? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人,
转载请联系作者并注明出处:http://www.betaflare.com/web/1736283814a1927087.html,
本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论