【发布时间】:2019-03-18 18:59:50
【问题描述】:
我也有 angular 6 应用程序在 azure 上运行良好,但我需要为一些服务器变量添加 server.js 文件,我在 root 上添加了 server.js 文件,例如
Server.js
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const http = require('http');
const app = express();
var router = express.Router();
const publicIp = require('public-ip');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false}));
// Angular DIST output folder
app.use(express.static(path.join(__dirname, 'dist/projectname')));
app.get('/getip', (req, res) => {
var ipcheck = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
(async () => {
console.log(await publicIp.v4());
res.json({
ip: await publicIp.v4(),
ip2: req.headers['x-forwarded-for'],
ip3: req.connection.remoteAddress,
ip4: req.ip
});
})();
});
// Send all other requests to the Angular app
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/projectname/index.html'));
});
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/prjectname/index.html'));
});
//Set Port
const port = process.env.PORT || '3000';
app.set('port', port);
const server = http.createServer(app);
server.listen(port, () => console.log(`Running on localhost:${port}`));
然后我转到 cmd 并运行 node server.js 它在本地主机上运行良好 但现在我想在 azure 服务器上做同样的事情如何部署它。 或者如何告诉 azure 总是 run node server.js
【问题讨论】:
-
是否要将其部署在 Azure WebApp 上?或者其他像 VM 或 Functions 的东西?或者您只是想知道如何使用合适的服务将其部署到 Azure。
-
webapp 我也有发布设置,但不知道如何通过 nodejs 运行它
标签: node.js angular azure visual-studio-2017