egg.js修改配置应用启动的端口号
/* eslint valid-jsdoc: "off" */
'use strict';
/**
* @param {Egg.EggAppInfo} appInfo app info
*/
module.exports = appInfo => {
/**
* built-in config
* @type {Egg.EggAppConfig}
**/
const config = exports = {};
exports.cluster = {
listen: {
port: 8885,
hostname: '127.0.0.1', // 不建议设置 hostname 为 '0.0.0.0',它将允许来自外部网络和来源的连接,请在知晓风险的情况下使用
// path: '/var/run/egg.sock',
}
}
// use for cookie sign key, should change to your own and keep security
config.keys = appInfo.name + '_1623400322146_7073';
// add your middleware config here
config.middleware = [];
// add your user config here
const userConfig = {
// myAppName: 'egg',
};
return {
...config,
...userConfig,
};
};
1.将egg项目除node_modules以外的文件压缩,使用xftp放入服务器并解压。我放在了/opt下
2.cd到解压的文件夹中,通过 npm install --production 安装项目依赖。
3. npm start 启动项目。
4.在前端将接口地址改为http://(服务器地址) ,这样就可以正常调用了
报错处理
降低 npm 版本
npm install npm@6.14.10 -g