我有2个文件夹:server和src。以下:angular2-express-starter
这是我的REPO
服务器/ app.ts:
import { routerUser } from "./routes/user";
const app: express.Application = express();
/* some stuff */
// api routes
// Set our api routes
app.use("/api/user", routerUser);
if (app.get("env") === "production") {
// in production mode run application from dist folder
console.log("PRODUCTION MODE");
app.use(express.static(path.join(__dirname, "/../client")));
}
/* some stuff */
的src /应用程序/ app.router.ts
import { Routes } from '@angular/router';
import { PostsComponent } from './posts/posts.component';
export const routes: Routes = [
{ path: '', pathMatch: 'full', redirectTo: 'user/profile'},
{ path: 'user/profile', component: PostsComponent }
];
关注here
我能够使用代理配置在单独的进程中运行服务器和客户端:
{
"/api/*": {
"target": "http://localhost:4300",
"secure": false
}
}
像这样:
tsc -p ./server/debug
node dist-debug/server/bin/www.js
ng server --host 0.0.0.0 --proxy-config proxy.conf.json
但是问题出现在生产模式中:将服务器和客户端都构建到dist文件夹中。
当我访问localhost:4300
时,它会自动重定向到localhost:4300/user/profile
,没关系。
但是,如果我直接访问localhost:4300/user/profile
页面回复:{"error":{},"message":"Not Found"}