# official_website **Repository Path**: bmycode/official_website ## Basic Information - **Project Name**: official_website - **Description**: TypeScript+Node.js+Koa+Vue.js 开发视频在线学习网站,后端分布式架构设计 - **Primary Language**: TypeScript - **License**: Not specified - **Default Branch**: master - **Homepage**: https://gitee.com/bmycode/official_website/ - **GVP Project**: No ## Statistics - **Stars**: 14 - **Forks**: 0 - **Created**: 2019-05-06 - **Last Updated**: 2022-05-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 注意 --- **这个项目每天都在开发中,并且目前阶段开源,你可以随意`git clone` 代码,然后每天从码云上拉取同步我的最新代码!如果你闲着蛋疼,那么可以参与进来和我一起进行项目的开发,有意向的 QQ 弹我。至于报酬?开玩笑..没有....但是能学到技术...!** > [必看的项目文档,正在编写完善中!!](https://gitee.com/bmycode/official_website/wikis/ready?sort_id=1450643) ## 技术栈 --- - 1: TypeScript - 2: Koa2.js(全家桶) - 3: jade + less - 4: GraphQL - 5: TypeOrm - 6: TypeDi - 7: class-validator - 8: Gulp - 9: Routing-controllers - 10: Require.js - 11: Vue.js(全家桶) & TypeScript - 12: Node.js - 13: Parcel - 14:Nginx 负载均衡 - 15: Docker - 16: Mysql,主从读写分离 - 17: Bmob 在线后端云 - 18: 七牛视频云存储方案 - 19: 阿里云免费 https 证书 - 20:Redis 主从,集群 - 21: SpringBoot 微服务全家桶技术 - ... 此处省略一万字 ## 简介 --- 纯手工搭建,并且正在开发,打算后期进行收费的在线学习官网,我给他起了一个名字 --> **怪客学堂**。PC官网用`Node.js` + `TypeScript` + `Koa2` 写的后端渲染,代码和开发套路都与`Java`,`Php`类似,同时采用大量的注解来开发,推荐稍微有点后端基础的看。 ```js import { JsonController, Body, Param, Post, Get, Action,UseInterceptor } from "routing-controllers"; import { config } from "../../config"; import { JsonResponseMiddlewares } from "../../middleware/JsonResponseMiddlewares"; import { Service,Inject } from "typedi"; import { PostServiceImpl } from "../../service/impl/PostServiceImpl"; import { Post as PostEntity } from "../../entity/PostEntity"; @Service() @JsonController(`${config.apiurl}/post`) @UseInterceptor(JsonResponseMiddlewares) export class PostControllerApi { @Inject() private postServiceImpl: PostServiceImpl /** * @api {post} /post/addPost addPost * @apiDescription 发布新闻的接口 * @apiName addPost * @apiGroup post * @apiParam {string} post_title 新闻标题 * @apiParam {string} post_author 新闻作者 * @apiParam {string} post_content 新闻内容 * @apiSuccessExample {json} 请求成功的返回: * { * "status":200, * "result":{ * } * } * @apiErrorExample {json} 请求失败的返回 * { * "status":404, * "result":{ * } * } * @apiSampleRequest http://geekhelp.cn/bmy/api/post/addPost * @apiVersion 1.0.0 */ @Post("/addPost") public async addPost(@Body({ validate: true }) post: PostEntity): Promise { return await this.postServiceImpl.addPostService(post) } } ``` `PC`端的前端页面使用`jade`模板引擎,`css` 预处理器使用的是`less`,使用`Require.js`进行前端js的模块化管理,`Gulp`进行`less`的编译和复制静态资源到指定`dist/`目录。 至于项目的管理员后台用 `Vue.js` + `TypeScript` 来写,使用了新的前端打包工具 `Parcel`进行项目打包,如果你只想看前端`Vue.js`+`TypeScript`+`Parcel`怎么写的,那么具体的管理后台源码路径为: [gitee.com/bmycode/admin](https://gitee.com/bmycode/official_website/tree/master/src/resources/view/admin) 至于前后端分离的数据交互,正在考虑打算使用 `GraphQL` 查询语言来做,具体还没想好,这么具有颠覆性的新技术,难道你不想在项目里面运用吗?..... 项目写完后准备分布式部署,所以还需要`Mysql`,`Nginx`,`Redis` 等一系列其他技术来支撑!! ## 问题记录 --- ### 1:routing-controllers 的坑 1 - Bug: 使用注解 `@Render` 渲染模板后,第二次访问其他页面但是展示效果还是上次的页面,页面不进行渲染 - 原因: 1:`action.renderedTemplate` 被放入`js`闭包中, 一旦中间件初始化,视图将永远不会改变。 2:根本原因在于框架的开发者团队对koa2不熟悉。 3:作者在忙 `GraphQL` 项目,没有时间继续维护。 - 路径:`node_modules/routing-controllers/driver/koa/KoaDriver.js` - 行数:`249`行 - 解决: 增加代码使用 `options.response.render`,强制渲染模板,然后删除原本的渲染代码 ```js return options.response.render(action.renderedTemplate, renderOptions_1); ``` - 注意: 其他开发者已经解决该问题,但开发者未合并修改到主分支也没有更新`npm`上的依赖包, 所以 `yarn add routing-controllers` 下载下来的还是有Bug的代码,需要自己手动修改插件源码 - 建议:下载 `routing-controllers` 的 `typescript` 源码,修改源码编译后上传到自己的`npm`市场,防止每次解决依赖后都需要重新修改框架源码,编译有难度和坑..mmp..... Github 问题反馈地址:[https://github.com/../434](https://github.com/typestack/routing-controllers/pull/434) Github 修复分支记录:[https://github.com/types..](https://github.com/typestack/routing-controllers/pull/434/files/001b45a416e3f1dbde33e7e91fadb09111d4061d)