MEAN堆栈应用程序无法在Ubuntu上运行(在本地工作)

时间:2018-02-19 11:03:34

标签: node.js angular express

我开发了一个简单的MEAN堆栈应用程序(使用Angular 4 for UI)。 它在我的本地Node中工作正常,但是当我在Ubuntu上部署它时,它会给出

未捕获的SyntaxError:意外的令牌< :在浏览器控制台中

这是我的app.js内容

const app = express();

const users = require('./routes/users');
const client = require('./routes/client');

// Port Number
//const port = 3000;
// Port Number
const port = process.env.PORT || 3001;

// CORS Middleware
app.use(cors());

// Set Static Folder
app.use(express.static(path.join(__dirname, 'public')));

// Body Parser Middleware
app.use(bodyParser.json());

// Passport Middleware
app.use(passport.initialize());
app.use(passport.session());

require('./config/passport')(passport);

app.use('/users', users);
app.use('/client', client);

// Index Route
app.get('/', (req, res) => {
  res.send('Invalid Endpoint');
});

app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname, 'public/index.html'));
});

// Start Server
app.listen(port, () => {
  console.log('Server started on port '+port);
});

我的index.html在公共文件夹下

    <html lang="en">
<head>
  <meta charset="utf-8">
  <title>MEAN</title>
  <base href=".">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">

  <!--Bootstrap and jQuery online links-->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

  <!-- For login Html -->
  <link rel="stylesheet" href="assets/icons/simple-line-icons.css">


</head>
<body>
  <app-root></app-root>
<script type="text/javascript" src="inline.bundle.js"></script><script type="text/javascript" src="polyfills.bundle.js"></script><script type="text/javascript" src="styles.bundle.js"></script><script type="text/javascript" src="vendor.bundle.js"></script><script type="text/javascript" src="main.bundle.js"></script></body>
</html>

1 个答案:

答案 0 :(得分:0)

尝试将'public'更改为:'/public',也许相对路径有帮助?