demo : Online Demo This project is not suitable for the development of large projects
(1) (https://github.com/guodonglw/koa_demo) This project has a cluster module example, which can use the system's multi-core to start multiple processes (2) (https://github.com/guodonglw/koa-practice) This project It can basically meet the needs of general pages. The project keywords are RESTful + koa + middleware + mysql + mongo. In actual development, middleware can be added and modified as needed.
node
// 将项目拉到本地
git clone 项目地址
// cd到本地项目下
cd ../vueProject
// 安装项目运行需要的依赖包
npm install / cnpm install (注:如需运行cnpm install,需先安运行npm install cnpm安装cnpm)
// 若在npm install后,提示需要执行npm audit fix则继续执行该命令
npm audit fix
// 在本地开发时,运行项目
npm run dev / cnpm run dev
Development environment, after completing the above steps, the browser accesses http://localhost:8082 and can jump to the corresponding page (advance chrome browser)
After completing the project development in the development environment, to publish the project to the server (such as nginx server), first fill in the request address (Server's interface address, which must be Wrap the url address in single quotes within double quotes. Because when you need to directly return the string path, you must use single quotes to enclose the string content, such as BASE_URL: "'http://192.168.1.111:4000/api'"), add the port number and '/ after the url api', this is due to F2FAdminServer The terminal interface uniformly uses the form of 'url' + ':' + 'port number' + '/api'. After completing the above modifications, perform the following operations.
// 项目打包
npm run build / cnpm run build
// 查看是否生成了dist文件夹
在文件夹下包括index.html文件和static文件,如作了标题旁的图片,可能还有logo.ico
// cd到dist文件夹下
cd ./dist/
// 将dist文件夹下的static的文件夹与index.html文件直接放在nginx服务器根目录下
// 配置nginx,在nginx.conf文件中修改所要监听的端口
// chrome浏览器访问对应的域名,如http://xxx.xxx.com:123/
如部署到个人服务器,没有域名,访问地址为http:// + ip + :端口号
After jumping to the login page, enter the corresponding account/password (such as: lilei/123456) in the database corresponding table (such as admin). If it jumps to the home page, the deployment is successful. Otherwise, according to the problem that occurs (press F12 Bring up the console to view), resolve any issues, and then repeat the above steps.
Server-side server deployment is divided into two parts: node.js server and MySQL database.
Method one
wget https://nodejs.org/dist/v4.4.4/node-v4.4.4-linux-x64.tar.xz
tar -xvf node-v4.4.4-linux-x64.tar
Method two
sudo apt-get node
After node is installed, you need to use npm to install the forever daemon module.
// 全局安装
npm install -g forever
// 启动项目进程
forever start app.js
// 重启项目进程
forever restart app.js
//停止项目进程
forever stop app.js
If you use your own server database, you need to install MySQL
// 数据库初始化
mysql –uroot –p </root/xxx.sql
// 安装项目依赖
npm install / cnpm install
// 若在npm install后,提示需要执行git audit fix则继续执行该命令
npm audit fix
// 临时启动项目(检查项目是否有错误)
node app.js
// 后台守护进程启动项目
forever start app.js
// vue项目config/prod.env.js修改(改为https的请求协议)
BASE_URL:"'https://xxx.xxx.xxx:111/api'"
// 项目打包(如果之前已经build过,需先执行rm -r dist)
npm run build
// dist文件夹下index.html与static放到nginx下
// 停止Server程序
forever stop app.js
// 将ssl的.crt,.key放到Server/cert目录下
// 安装必要模块
npm install http --save -d (加--save -d会将模块名写入package.json中,下次npm install即可安装该模块)
npm install https --save -d
npm install fs --save -d
// app.js开始部分添加代码
var http = require('http');
var https = require('https');
var fs = require('fs');
// Configuare https
const httpsOption = {
key : fs.readFileSync("./cert/.key"),
cert: fs.readFileSync("./cert/.crt")
}
// app.js末尾部分代码修改
http.createServer(app).listen(4001 ,function(){
console.log("Listening on port:" + 1000);
});
https.createServer(httpsOption, app).listen(
1001,function(){
console.log("Listening on port:" + 1001);
});
// 至此,https已经配置完成