Git Product home page Git Product logo

blog-backend's Introduction

前后端分离实践----blog's backend

前端地址---- blog's frontend

简介:通过vue.js框架与koa2框架分别搭建前后端,利用ngnix端口分发部署实现代码全分离,开发全分离。

nginx文件配置内容

   server {
   	listen       80;
   	server_name  localhost;
   	location / {
   	    proxy_pass http://127.0.0.1:8080;               #转发非api,与上传的静态资源的其他信息 
   	    proxy_redirect default;
   	}
   	location /api/ {
   	    proxy_pass http://127.0.0.1:3000/api/;          #转发至api接口
   	}
   		location ^~ /uploads/ {
   	    proxy_pass http://127.0.0.1:3000/uploads/;     #转发至上传的静态资源
   	}
   }

Getting Start

1. 开发环境
node.js 7.6+
mognodb 3.0+
2. 依赖于mongodb数据库

      先安装 mongodb 数据库,安装完成后运行数据库,开启27017(默认)端口

3. 克隆到本地,安装依赖,运行
> git clone https://github.com/FantasyGao/blog-backend.git
> cd blog-backend
> npm install 
> npm start

简要概述

1. 全部使用ES6语法,aysnc+await结构

2. 通过mongoose模块+promise模块操作mongodb数据库

3. 由jsonwebtoken模块完成权限控制

4. (可选)koa-sslify 模块,实现https,需要ssl证书和密钥

5. koa-multer模块协助完成静态文件上传

目录结构

➜  backend
.
├── README.md
├── app.js
├── node_modules
├── package.json
├── public
│   ├── images
│   ├── dist
│   └── upoloads
├── ssl
│   ├── server.cert
│   └── server.key
├── db
│   ├── config.js
│   └── model.js
├── api
│   ├── articleAPI.js
├── ├── userAPI.js
│   └── logAPI.js
├── route
│   ├── api.js
├── ├── auth.js
│   └── other.js
└── views
    ├── err.ejs
    └── index.ejs

License

MIT

blog-backend's People

Contributors

fantasygao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

blog-backend's Issues

请教作者2个问题~

1.本地如何打开后台管理系统?
已经打开了MongoDB但是没有数据,localhost:8080/admin/login中输入账号和密码后,无法登陆,报错

GET http://localhost:7002/api/login?user=admin&password=d29cff3068d6d25e2d0d32fa3090f92642d53376 net::ERR_CONNECTION_REFUSED

2.发现后台页和前端页都写在了一个front-end项目中,那您是怎样将其分开两个端口请求,然后再实现跨域的?

PS:线上体验很良心👍

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.