angular2 cli를 사용하여 프로젝트를 만들었습니다. 또한 백엔드 역할을하는 별도의 노드 js 응용 프로그램을 만들었습니다. 프론트 엔드 애플리케이션을 노드 애플리케이션으로 이동하여 노드 server.js를 사용하여 두 애플리케이션을 모두 실행할 수 있습니다. 내 server.js는 다음과 같습니다동일한 폴더에서 Angular2 CLI Project 및 Node.js 앱을 설정하는 방법
app.use(express.static(__dirname + '/app'));
...
app.get('*', function (req, res) {
res.sendfile('./app/src/index.html');
});
app.listen(8000);
angular2의 CLI에서 내 index.html을은 다음과 같습니다 : 지금 노드 server.js를 실행하고 http://localhost:8000/를 찾아
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>My App</title>
<base href="/">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root>Loading...</app-root>
</body>
"Loading ..."메시지를 볼 수는 있지만 아무 것도 나타나지 않고 콘솔에 오류가 없습니다.
잘못된 위치'/ app/src/index.html'을 참조하고 있습니다. 'app' 디렉토리에서 파일을 제공하는 노드 응용 프로그램이기 때문에'/ src/index.html'이어야합니다. 'app.use (express.static (__ 디렉토리 이름 + '/ app'))'. 따라서'/ app'를 루트로 고려하여 위치를 직접 참조해야합니다. –
@KunalSharma 브라우저에 "Loading ..."레이블이 표시되어 위치가 정확한지 확인할 수 있습니다. 나는 그것을 어쨌든 변경하려고 시도하고 "Error : ENOENT : no such file or directory"오류를 받았습니다. –
plnkr을 업로드해야합니다. 아마도 도움이 될 것입니다. 어떤 종류의 경로 참조 문제 일 수 있습니다. 콘솔의 네트워크 탭을 확인하십시오. –