Giter VIP home page Giter VIP logo

vue-blog's Introduction

vue-blog

A single-user blog built with vue2, koa2 and mongodb which supports Server-Side Rendering

一个使用vue2、koa2、mongodb搭建的单用户博客,支持markdown编辑,文章标签分类,发布文章/撤回发布文章,支持服务端渲染(Server-Side Rendering)


访问链接:https://imhjm.com/

整体架构

  • client端分为frontadminwebpack2打包实现多页配置,开发模式下hot reload
    • admin端使用vue2、vuex、vue-router
    • front端直接使用 vue event bus vuex(考虑到今后博客应用可能变复杂)、vue-router, Fastclick解决移动端300ms延迟问题
    • 编辑器使用simplemde
    • markdown解析和高亮使用marked.js和highlight.js
  • server
    • 使用koa2+koa-router实现RESTful API
    • mongoose连接mongodb
    • 前后端鉴权使用jwt
  • 实现Server-Side Rendering服务端渲染

更多细节

访问博客线上地址可以获得最新信息

快速开始

  • 需要Node.js 6+版本
  • 需要安装mongodb,并且运行mongodb服务,在server/configs/index.js中默认连接mongodb://localhost:27017/vue-blog
  • 配置server/configs/index.js,配置admin用户名、密码等,或者新建server/configs/private.js

注:可使用docker快速开始,详见后文

# install dependencies 
# 安装依赖,可以使用yarn/npm
npm install # or yarn install

# serve in dev mode, with hot reload at localhost:8889
# 开发环境,带有HMR,监听8889端口
npm run dev

# build for production
# 生产环境打包
npm run build

# serve in production mode (with building)
# 生产环境服务,不带有打包
npm start

# serve in production mode (without building)
# 生产环境服务,带有打包
npm run prod

# pm2
# need `npm install pm2 -g`
npm run pm2

使用docker快速开始

# development mode(use volumes for test-edit-reload cycle)
# 开发模式(使用挂载同步容器和用户主机上的文件以便于开发)
# Build or rebuild services
docker-compose build
# Create and start containers
docker-compose up

# production mode
# 生产模式
# Build or rebuild services
docker-compose -f docker-compose.prod.yml build
# Create and start containers
docker-compose -f docker-compose.prod.yml up

# 进入容器开启交互式终端
# (xxx指代容器名或者容器ID,可由`docker ps`查看)
docker exec -it xxx bash

注:为了防止生产环境数据库被改写,生产模式数据库与开发环境数据库的链接不同,开发环境使用vue-blog,生产环境使用vue-blog-prod,具体可以看docker-compose配置文件

自定义配置

server端配置文件位于server/configs目录下

// 可新建private.js定义自己私有的配置
module.exports = {
    mongodbSecret: { // 如果mongodb设置用户名/密码可在此配置
        user: '', 
        pass: ''
    },
    jwt: { // 配置jwt secret
        secret: ''
    },
    admin: { // 配置用户名/密码
        user: '',
        pwd: ''
    },
    disqus: { // disqus评论
        url: '',
    },
    baidu: { // 百度统计
        url: '',
    },
}

LICENSE

MIT

vue-blog's People

Contributors

bupt-hjm 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-blog's Issues

关于使用jwt的一些问题

  • 我同样在项目中使用了jwt进行登入校验,但是发现一个问题,就是由于后台和前台使用的是一套的node接口;这样我在进入前台进行接口请求的时候会被同样执行jwt的token的验证,其实这是不必要的,我开始想到的是对前台和后台请求同一套接口的时候进行传递一个特定参数进行有效的区别,但是这样的方式特别低效,请问您是怎么解决这个问题的呢

TO DO

  • 支持评论
  • 移动端查看大图
  • disqus优化
  • pwa & server push支持

测试环境和生产环境在360浏览器的兼容问题

你好,我在访问您的网站的时候发现一个很神奇的问题,不清楚是我本地环境的原因还是,浏览器默认的问题,还是代码兼容的问题,问题如下
1、通过你的http://123.206.67.156:9000/这个地址在360安全浏览器访问,打开开发者工具,弹出的竟然是ie的内核那种,并且默认的竟然是ie7,此时片空白,然后切换到ie9的仿真也是一样的只有ie10以上才行
2、同样通过http://123.206.67.156:9000/这个地址访问在ie浏览器器确实正常的...
3、使用域名的地址访问,在ie,360上都是正常的
请问你是做过处理还是什么原因

如何添加新的博客?

很棒的项目。
npm run dev之后界面空空如也,如何写新的博客呢?
前端小白一枚。。

打包的时候出现的问题

ERROR in modules/admin.06a91d44.min.js from UglifyJs
Unexpected token: operator (>) [modules/admin.06a91d44.min.js:68,23]

ERROR in modules/front.d96e9ae6.min.js from UglifyJs
Name expected [modules/front.d96e9ae6.min.js:46,6]
  • webpack的配置,和您的是一样的但是构建的shih时候出现这个问题。。。。

这是在生产环境下,出现的问题,开发环境没问题,修改UglifyJs插件后虽然构建了但是页面保存提示意外的< 并且图片资源无法显示。。。。

请教一个关于 koa-onerror 的问题

version:
"koa": "^2.3.0",
"koa-onerror": "^3.1.0"

import onerror from "koa-onerror";
const app = new Koa();
onerror(app);

ctx.throw(500, '服务器错误')

为何 onerror(app), 拦截 ctx.throw 抛出的错误,会返回一个 html 格式的错误文档,而不是一个json格式的错误?(即如何拦截返回一个如下格式的error: ctx.body = {status: 500, message: '服务器错误'})

ie浏览器下页面报错(ie11)

您好,最近下了您的代码下来跑了下,发现在ie下程序出错,浏览器版本为ie11,麻烦有时间帮忙看下问题出在哪里了,谢谢,以下为报错的截图:
image

image

nodejs 7 可以开启支持async和await的模式了

nodejs 7.0.0 开始已经支持使用 --harmony-async-await 选项来开启async 和 await功能

可以不必用babel转了。后端koa直接用node写async和await原生支持。前端用vue-cli的webpack模板的es6足够了

你好,关于服务器渲染的问题

你好,老师
<music-list
@bankDetail="bankDetail"
:platform="perkList.platform"
:data="perkList.songList">

如果父组件里面,怎么把子组件的dom的节点渲染到源代码上,这个问题,怎么处理,非常感谢!

Unexpected token < with SSR

Hi, @BUPT-HJM, first of all thank you a lot for this project, its pretty nice.
But I face problem while using external library at front end. I need slider functionality for first page with article list. I tried to use:

- https://github.com/NightCatSama/vue-slider-component - this component export js file, and it use document inside it.
My error in this case is - ReferenceError: document is not defined while I'm doing
import slider from 'vue-slider-component'

- My second choice is https://github.com/ktsn/vue-range-slider
My error in this case is - ReferenceError: window is not defined while I'm doing
import 'vue-range-slider/dist/vue-range-slider.css'

- Then I tried to use vue-slider-component another way to connect
My error in this case is - SyntaxError: Unexpected token < while I'm doing
import vueSlider from 'vue-slider-component/src/vue2-slider.vue'

So, question is - what is the right and best way to import external component to front-end of your project?
Thank you forward.

npm run dev报错

{ app: { port: 8889, baseApi: '/api' },
mongodb: { url: 'mongodb://localhost:27017/vue-blog' },
jwt: { secret: 'me' },
mongodbSecret: { user: 'andy', pass: '123456' },
admin: { user: 'admin', pwd: '123456' } }
C:\WorkSpace\Project\nodejs\vue-blog\node_modules\require-dir\index.js:97
if (!require.extensions.hasOwnProperty(ext)) {
^

TypeError: require.extensions.hasOwnProperty is not a function
at requireDir (C:\WorkSpace\Project\nodejs\vue-blog\node_modules\require-dir\index.js:97:37)
at importDir (C:\WorkSpace\Project\nodejs\vue-blog\node_modules\import-dir\index.js:31:17)
at Object. (C:/WorkSpace/Project/nodejs/vue-blog/server/api/index.js:6:16)
at Module._compile (module.js:624:30)
at loader (C:\WorkSpace\Project\nodejs\vue-blog\node_modules\babel-register\lib\node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (C:\WorkSpace\Project\nodejs\vue-blog\node_modules\babel-register\lib\node.js:154:7)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at Function.Module._load (module.js:500:3)
at Module.require (module.js:568:17)
at require (internal/module.js:11:18)
at Object. (C:/WorkSpace/Project/nodejs/vue-blog/server/index.js:9:1)
at Module._compile (module.js:624:30)
at loader (C:\WorkSpace\Project\nodejs\vue-blog\node_modules\babel-register\lib\node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (C:\WorkSpace\Project\nodejs\vue-blog\node_modules\babel-register\lib\node.js:154:7)
at Module.load (module.js:545:32)
[nodemon] app crashed - waiting for file changes before starting...

one question:

看了博主的文章之后,也有了准备着手搭个自己的博客的冲动😂。还有一个问题,就是博客没有评论系统。顺便请问博主,文章里面那个关于博客的系统结构图是用什么软件画的呢?

token问题

请问ssr 你的token存到哪里的? 因为在client和server调用接口都要用到, 所以放到localStorag里server取不到,放到cookie里client也取不到

请教一个mongoose的问题

直接贴代码

/server/controllers/articles_controller.js

```js
  let createResult = await article.save().catch(err => {
    ctx.throw(500, '服务器内部错误')
  });
  await Article.populate(createResult, { path: 'tags' }, function(err, result) {
    createResult = result;
    // console.log(result)

  });

查阅了许久的文档,也也看到这个pupulate可以这样使用,直接传入一个model的实例?请问这个是怎么处理的?

重构

你好,我正在学习ssr以及koa2想,通过您的项目一手一步步的搭建,但是在书写启动服务的入口文件的时候,有些蒙了,比如环境的判断
image
书写到这里的时候,我发现,可能自己还没弄懂您整个项目的构建过程,所以,你方便的话,可以和我说下您在搭建这个项目的时候整个构建思路么,以及架构的流程。Thanks♪(・ω・)ノ

一个渲染的问题

我想问下,您存到数据库的数据是html还是什么,我存入数据库的是html标签,但是当我渲染的时候直接输出的是html便签,并没有把html标签解析

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.