blog

前后端分离+服务端渲染的博客系统. 基于Vue2、Koa2、MongoDB、Redis

APACHE-2.0 License

Stars
642
Committers
3

Blog

A blog system. Based on Vue2, Koa2, MongoDB and Redis

  • , SPA + RESTful

Demo

https://smallpath.me https://smallpath.me/post/blog-back-v2

Table of Contents

TODO

TODO

  • Node v6
  • pm2
  • MongoDB
  • Redis

server

confconfig.tpl, config.js

:

  • tokenSecret

  • defaultAdminPassword
    • , ,

mongoDBredis

  • mongoHost
  • mongoDatabase
  • mongoPort
  • redisHost
  • redisPort

:

  • qiniuAccessKey

  • qiniuSecretKey

  • qiniuBucketHost
    • Bucket
  • qiniuBucketName
    • Bucket
  • qiniuPipeline

npm install
pm2 start entry.js

RESTful3000

front

servermongo.tpl, mongo.js

mongoDBmongo.js:

  • mongoHost
  • mongoDatabase
  • mongoPort
npm install
npm run build
pm2 start production.js

logo.png``favicon.ico``static

nginx8080,

server{
    listen 80;                                      #https, 80443
    server_name *.smallpath.me smallpath.me;        #
    root /alidata/www/Blog/front/dist;       #dist
    set $node_port 3000;
    set $ssr_port 8080;

    location ^~ / {
        proxy_http_version 1.1;
        proxy_set_header Connection "upgrade";
        proxy_pass http://127.0.0.1:$ssr_port;
        proxy_redirect off;
    }

    location ^~ /proxyPrefix/ {
        rewrite ^/proxyPrefix/(.*) /$1 break;
        proxy_http_version 1.1;
        proxy_set_header Connection "upgrade";
        proxy_pass http://127.0.0.1:$node_port;
        proxy_redirect off;
    }

    location ^~ /dist/ {
        rewrite ^/dist/(.*) /$1 break;
        etag         on;
        expires      max;
    }

    location ^~ /static/ {
        etag         on;
        expires      max;
    }
}

8080

admin

npm install
npm run build

nginxdist,

server{
    listen 80;                                     #https, 80443
    server_name admin.smallpath.me;                #
    root /alidata/www/Blog/admin/dist;       #dist
    set $node_port 3000;

    index index.js index.html index.htm;

    location / {
        try_files $uri $uri/ @rewrites;
    }

    location @rewrites {
        rewrite ^(.*)$ / last;
    }

    location ^~ /proxyPrefix/ {
        rewrite ^/proxyPrefix/(.*) /$1 break;
        proxy_http_version 1.1;
        proxy_set_header Connection "upgrade";
        proxy_pass http://127.0.0.1:$node_port;
        proxy_redirect off;
    }

    location ^~ /static/ {
        etag         on;
        expires      max;
    }
}

8082

RESTful API

3000 , IP, nginx , /proxyPrefix

, demoAPI:

https://smallpath.me/proxyPrefix/api/:modelName/:id

, :modelName, 6

post
theme
tag
category
option
user

:idID, CRUD

HTTP

:

GET     //
POST    //
PUT     //
PATCH   //
DELETE  //ID

:

    • header Content-Type application/json , body body JSON
    • headerContent-Type``application/json, JSON

userGET

user, GET , header authorization Token, CRUD

Token

POST https://smallpath.me/proxyPrefix/admin/login

body:

{
	"name": "admin",
	"password": "testpassword"
}

, token JSON

{
  "status": "success",
  "token": "tokenExample"
}

, JSON :

{
  "status": "fail",
  "description": "Get token failed. Check name and password"
}

token, token , header authorization Token,

Token

POST https://smallpath.me/proxyPrefix/admin/logout

header``authorization token, token

Token

Token , Token , tokenExpiresIn,

user GET , Token

URI mongoDB , :

conditions,
select,
count,
sort,
skip,
limit

(conditions)

JSON, , mongoose.find

GET https://smallpath.me/proxyPrefix/api/post

title''

GET https://smallpath.me/proxyPrefix/api/post?conditions={"title":""}

id

GET https://smallpath.me/proxyPrefix/api/post/?conditions={"_id":{"$lt":"580b3ff504f59b4cc27845f0"}}&sort=1&limit=1

select

JSON, ,

title''

GET https://smallpath.me/proxyPrefix/api/post?conditions={"title":""}&select={"createdAt":1,"updatedAt":1}

count

GET https://smallpath.me/proxyPrefix/api/post?conditions={"type":0}&count=1

sort

id

GET https://smallpath.me/proxyPrefix/api/post?sort={"_id":-1}

GET https://smallpath.me/proxyPrefix/api/post?sort={"updatedAt":-1}

skip limit

2(10)

GET https://smallpath.me/proxyPrefix/api/post?limit=10&skip=10&sort=1

Token

POST https://smallpath.me/proxyPrefix/api/:modelName

BodyJSON

, Schema

Token

PUT https://smallpath.me/proxyPrefix/api/:modelName/:id

:id``_id, BodyJSON

Token

PATCH https://smallpath.me/proxyPrefix/api/:modelName/:id

:id``_id, BodyJSON

PATCH``PUT

Token

DELETE https://smallpath.me/proxyPrefix/api/:modelName/:id

ID

Related Projects