我如何使用:
https://github.com/gdi2290/angular-starter
使用快递框架?我可以很好地启动webpack dev服务器,但我想使用像cookieparser(https://www.npmjs.com/package/cookie-parser)这样的过多库。
虽然npm start使用webpack-dev-server,但我不知道使用哪个文件来放入app.use语句并导入cookieparser ..
答案 0 :(得分:1)
在撰写本文时,请使用以下内容更新webpack.dev.js:
node: {
global: true,
crypto: 'empty',
process: true,
module: false,
clearImmediate: false,
setImmediate: false,
fs: 'empty',
net: 'empty'
}
一切都应该按照预期的那样发挥作用。
答案 1 :(得分:1)
只是想跳进去告诉你我有一个与前端角度服务器对话的快速服务器,我将它们分开构建,所以我不会用冗余库填充其中一个,然后一旦我准备好了我只需要构建'dist'的路径指向我的服务器文件夹,如下所示:
"apps": [
{
"root": "src",
"outDir": "server/dist", //<--- Here, I point to where my server.js, so i can simply build and its ready for production
"assets": [
"assets",
"favicon.ico"
],
这是我使用node server.js
启动的整个server.jslet express = require('express');
let passport = require('passport');
let session = require('express-session');
const config = require('./server/auth/config');
let oauth2orize = require('oauth2orize');
const app = express();
const cors = require('cors');
const html = __dirname + '/dist';
app.use(passport.initialize());
app.use(passport.session());
app.use(cors());
app.options('*', cors());
app.use('/api', require('./server/misc/routemanager'));
/**
* This line tells the server to provide our angular site (after running ng build with it)
*/
app.use(express.static(html));
app.get('*', function(req, res) {
res.sendFile(html + '/index.html')
});
app.listen(4949, () => {
console.log(`Node Express server listening on http://localhost:4949`);
});
现在我可以建立我的快速后端,但是我希望通过路由与它交谈,并且仍然在一个节点启动中启动整个事情