我可以用nodejs(express)连接已创建的角度项目吗?
我已经创建了一个有角度的网站,我已完成路由并连接到firestore。但现在我想要一个中间件连接,因为我希望RFID扫描仪(Rasberry PI)扫描的值存储在firestore中。那么我可以将此角度项目与节点连接起来,或者我是否需要重建我的应用程序?
我已经尝试使用节点js进行连接,但是当我运行服务器时,屏幕是空白的,只显示标题
------ IN SERVER.js ---------
const express = require('express');
const path = require('path');
const http = require('http');
// const bodyParser = require('body-parser');
// const morgan = require('morgan');
const proxy = require('express-http-proxy');
// const cors = require('cors');
const request = require('request');
const app = express();
// app.use(cors());
// Point static path to dist
app.use(express.static(path.join(__dirname, 'dist')));
// Catch all other routes and return the index file
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
/**
* Get port from environment and store in Express.
*/
const port = process.env.PORT || '3001';
app.set('port', port);
/**
* Create HTTP server.
*/
const server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port, () => console.log(`API running on ${port}`));
-------在DIST / index.html --------
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Miracle Bus Track</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="+Icons" rel="stylesheet">
<link href="" rel="stylesheet">
</head>
<body>
<app-root></app-root>
</body>
</html>
回答如下:
答案是'是',因为客户端JS UI通常与后端分离,可以在任何地方托管。
但是,您的具体问题听起来像是一个代码/构建问题,Stackoverflow不是一个很好的解决方法。我看到的一件事是你没有在角度javascript的任何地方引用标签,所以你应该从那里开始。
我可以用nodejs(express)连接已创建的角度项目吗?
我已经创建了一个有角度的网站,我已完成路由并连接到firestore。但现在我想要一个中间件连接,因为我希望RFID扫描仪(Rasberry PI)扫描的值存储在firestore中。那么我可以将此角度项目与节点连接起来,或者我是否需要重建我的应用程序?
我已经尝试使用节点js进行连接,但是当我运行服务器时,屏幕是空白的,只显示标题
------ IN SERVER.js ---------
const express = require('express');
const path = require('path');
const http = require('http');
// const bodyParser = require('body-parser');
// const morgan = require('morgan');
const proxy = require('express-http-proxy');
// const cors = require('cors');
const request = require('request');
const app = express();
// app.use(cors());
// Point static path to dist
app.use(express.static(path.join(__dirname, 'dist')));
// Catch all other routes and return the index file
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
/**
* Get port from environment and store in Express.
*/
const port = process.env.PORT || '3001';
app.set('port', port);
/**
* Create HTTP server.
*/
const server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port, () => console.log(`API running on ${port}`));
-------在DIST / index.html --------
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Miracle Bus Track</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="+Icons" rel="stylesheet">
<link href="" rel="stylesheet">
</head>
<body>
<app-root></app-root>
</body>
</html>
回答如下:
答案是'是',因为客户端JS UI通常与后端分离,可以在任何地方托管。
但是,您的具体问题听起来像是一个代码/构建问题,Stackoverflow不是一个很好的解决方法。我看到的一件事是你没有在角度javascript的任何地方引用标签,所以你应该从那里开始。