以下是我的./server.js
我的角度距离是./client/dist
,当我node server.js
在终端中我的角度应用和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'));
});
答案 0 :(得分:1)
我创建了一个现代的MEAN Stack指南,其中包含完整的教程和源代码。特别是对于您的问题,我创建了有关如何将MEAN堆栈应用程序部署到AWS Elastic Beanstalk(https://www.meankit.io/guides/deploy-with-aws)
的分步指南如果您需要更多信息,也可以参考链接。