myApp-
|-dist -
|- myApp -
|- index.html
|- main.js
|-server-
|- app.js
|-src-
| - app
| - assets
| - index.html
| - main.ts
我的
app.js
文件
var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var http = require('http');
var app = express();
var port = process.env.PORT || 3000;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(express.static(path.join(__dirname, 'dist')));
app.get('/',(req,res)=> {
res.sendFile(path.join(__dirname, '../dist/myApp/index.html'));
});
var server = http.createServer(app);
server.listen(port, ()=>{
console.log('Server running at port ', port)
});
角度文件与默认值相同
但它只显示了一个空页。
我知道它正在接近
index.html
因为它更改了index.html中标题的名称,但是没有到达
app.component.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>BtechApp</title>
<base href="/BtechApp">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
当我检查那一页时,它显示出错误
Uncaught SyntaxError: Unexpected token <
另外,我在网上查到app.js中index.html的路径是
dist -
| - index.html
但在我看来
dist -
| - myApp -
| - index.html
-我发现问题出在app.js文件中,你可以在下面查看我的答案。