【发布时间】:2018-09-14 12:34:45
【问题描述】:
以下是我的./server.js,当我在终端中node server.js 时,我的角度分布在./client/dist,我的角度应用程序和nodejs 后端按预期工作。现在如何在 aws beanstalk 上部署(我愿意更改 beanstalk)?
大多数教程都希望我从头开始工作,但我确实需要服务器像在 localhost 上那样工作,如下所示。
const express = require('express');
const colors = require('colors');
const bodyParser = require('body-parser');
const compression = require('compression');
const path = require('path');
const fs = require('fs');
const cors = require('cors');
// init "app"
const app = express();
var staticRoot = __dirname + '/client/dist/';
app.set('port', (process.env.PORT || 5000));
app.use(cors({origin: `http://localhost:4200`}));
//parse incoming data before routes
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
// api routes
app.use('/api',require('./api/api'));
app.use(function(req, res, next) {
//if the request is not html then move along
var accept = req.accepts('html', 'json', 'xml');
if (accept !== 'html') {
return next();
}
// if the request has a '.' assume that it's for a file, move along
var ext = path.extname(req.path);
if (ext !== '') {
return next();
}
fs.createReadStream(staticRoot + 'index.html').pipe(res);
});
app.use(express.static(staticRoot));
app.listen(app.get('port'), function() {
console.log('app running on port', app.get('port'));
});
【问题讨论】:
-
我不会减一;但是,请改为评论。这个问题和角度有什么关系...
-
拥有 Angular 应用程序的人可能知道如何使用节点后端部署它们?
标签: node.js express amazon-ec2 amazon-elastic-beanstalk