如何将angular + ejs app与节点

时间:2017-09-11 15:07:20

标签: angularjs node.js ejs

我有使用ejs + angularJs 1.0开发并在节点服务器上运行的Web应用程序。由于这些ejs + angular只提供静态文件,我想让我的应用程序在webserver中运行。目前,URL映射是在节点app.js中完成的,因此如果我们加载URL,它将从ejs呈现html。有关更多信息,我添加了节点app.js配置:

app.set('title', wsConfig.title); 
app.use(bodyParser.json()); 
app.engine('.html', ejs.__express); 
app.set('view engine', 'ejs'); 
app.use(express.static('./public'));
app.set('views', path.join(__dirname, 'public')); // Set the views path

app.use(function(req, res, next) {
if (req.url.substr(-1) == '/' && req.url.length > 1)
    res.redirect(301, req.url.slice(0, -1));
else
    next();
});

app.get('/', function(req, res) {
  res.render('login', { title: wsConfig.title });
});

app.get('/home', function(req, res) {
  res.render('index', { title: wsConfig.title });
});

因此,我需要使用js和渲染ejs文件构建一个dist文件夹,而不是使用节点服务器进行渲染。这样我就可以在web服务器中部署这个dist目录。我想用webpack来完成这个。请提出我们的建议。

0 个答案:

没有答案