A blog system. Based on Vue2, Koa2, MongoDB and Redis
https://smallpath.me https://smallpath.me/post/blog-back-v2
confconfig.tpl
, config.js
:
tokenSecret
defaultAdminPassword
mongoDBredis
mongoHost
mongoDatabase
mongoPort
redisHost
redisPort
:
qiniuAccessKey
qiniuSecretKey
qiniuBucketHost
qiniuBucketName
qiniuPipeline
npm install
pm2 start entry.js
RESTful3000
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
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
3000 , IP, nginx , /proxyPrefix
, demoAPI:
, :modelName
, 6
post
theme
tag
category
option
user
:id
ID, CRUD
:
GET //
POST //
PUT //
PATCH //
DELETE //ID
:
Content-Type
application/json
, body
body
JSONContent-Type``application/json
, JSONuser
GET
user
, GET , header authorization
Token, CRUD
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,
header``authorization
token, token
Token , Token
, tokenExpiresIn
,
user
GET , Token
URI mongoDB , :
conditions,
select,
count,
sort,
skip,
limit
JSON, , mongoose.find
GET https://smallpath.me/proxyPrefix/api/post?conditions={"title":""}
JSON, ,
GET https://smallpath.me/proxyPrefix/api/post?conditions={"type":0}&count=1
GET https://smallpath.me/proxyPrefix/api/post?sort={"_id":-1}
GET https://smallpath.me/proxyPrefix/api/post?sort={"updatedAt":-1}
GET https://smallpath.me/proxyPrefix/api/post?limit=10&skip=10&sort=1
Token
BodyJSON
, Schema
Token
:id``_id
, BodyJSON
Token
:id``_id
, BodyJSON
PATCH``PUT
Token
ID