cnodejs / egg-cnode Goto Github PK
View Code? Open in Web Editor NEWCNode 社区 Egg 版本
Home Page: https://cnodejs.org/
License: MIT License
CNode 社区 Egg 版本
Home Page: https://cnodejs.org/
License: MIT License
RT
gist $ ./cloc-git https://github.com/cnodejs/nodeclub.git
194 text files.
194 unique files.
12 files ignored.
github.com/AlDanial/cloc v 1.76 T=1.09 s (170.3 files/s, 66779.9 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
JavaScript 125 6577 10539 34314
CSS 11 2528 101 14147
HTML 43 300 9 2266
LESS 1 220 12 1085
Markdown 2 30 0 238
JSON 1 0 0 69
make 1 13 1 47
YAML 1 8 0 21
-------------------------------------------------------------------------------
SUM: 185 9676 10662 52187
-------------------------------------------------------------------------------
gist $ ./cloc-git https://github.com/cnodejs/egg-cnode.git
154 text files.
154 unique files.
12 files ignored.
github.com/AlDanial/cloc v 1.76 T=1.08 s (133.7 files/s, 64530.8 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
JavaScript 87 6306 10269 32023
CSS 11 2528 101 14147
HTML 38 259 9 2185
LESS 1 221 12 1088
Markdown 2 45 0 115
YAML 3 7 6 94
JSON 1 0 0 67
Dockerfile 1 8 1 8
-------------------------------------------------------------------------------
SUM: 144 9374 10398 49727
-------------------------------------------------------------------------------
Summary:
关于搜索alsotang大神坚持谷歌最好,但是国内翻墙不方便,能否加个 百度的 ,检测到被墙切换到百度。实现双站切换。当然如果练习node,最好做个本站搜索 如何分词什么的 。
exports.index = function (req, res, next) {
var q = req.query.q;
q = encodeURIComponent(q);
q1='+q+'&q2=&q3=&q4=&rn=10&lm=0&ct=0&ft=&q5=&q6=plmclub.org&tn=baiduadv');
res.redirect('https://cnodejs/cse/search?q='+q+'&s=6701441402440425312&nsid=0');
};
环境:centos:7.2
[email protected] assets /root/egg-cnode
loader app/view app/
Scaned. 3 asset(s) will be build.
Building... /public/editor.min.js
processing... /public/libs/editor/editor.js ..build .. use 3692ms.
processing... /public/libs/webuploader/webuploader.withoutimage.js ..build .. use 1519ms.
processing... /public/libs/editor/ext.js ..build .. use 53ms.
✔ Done. Build time 5271 ms.
Building... /public/stylesheets/index.min.css
processing... /public/libs/bootstrap/css/bootstrap.css ..build .. use 436ms.
processing... /public/stylesheets/common.css ..build .. use 4ms.
processing... /public/stylesheets/style.less ..build .. use 142ms.
processing... /public/stylesheets/responsive.css ..build .. use 36ms.
processing... /public/stylesheets/jquery.atwho.css ..build .. use 2ms.
processing... /public/libs/editor/editor.css ..build .. use 45ms.
processing... /public/libs/webuploader/webuploader.css ..build .. use 1ms.
processing... /public/libs/code-prettify/prettify.css ..build .. use 15ms.
processing... /public/libs/font-awesome/css/font-awesome.css ..build .. use 25ms.
✔ Done. Build time 709 ms.
Building... /public/index.min.js
processing... /public/libs/jquery-2.1.0.js ..build .. use 1827ms.
processing... /public/libs/lodash.compat.js ..build .. use 1291ms.
processing... /public/libs/jquery-ujs.js ..build .. use 82ms.
processing... /public/libs/bootstrap/js/bootstrap.js ..build .. use 339ms.
processing... /public/libs/jquery.caret.js ..build .. use 83ms.
processing... /public/libs/jquery.atwho.js ..build .. use 202ms.
processing... /public/libs/markdownit.js ..build .. use 1057ms.
processing... /public/libs/code-prettify/prettify.js ..build .. use 159ms.
processing... /public/libs/qrcode.js ..build .. use 430ms.
processing... /public/javascripts/main.js ..build .. use 11ms.
processing... /public/javascripts/responsive.js ..build .. use 23ms.
✔ Done. Build time 5516 ms.
🏁 Compile static assets done. Build time 11506 ms.
assets.json is here: /root/egg-cnode/app/assets.json
fs.js:124
throw new ERR_INVALID_CALLBACK();
^
TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
at maybeCallback (fs.js:124:9)
at Object.fs.writeFile (fs.js:1244:14)
at Object. (/root/egg-cnode/node_modules/loader-builder/bin/builder:49:4)
at Module._compile (internal/modules/cjs/loader.js:678:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
at Module.load (internal/modules/cjs/loader.js:589:32)
at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
at Function.Module._load (internal/modules/cjs/loader.js:520:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)
at startup (internal/bootstrap/node.js:228:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:575:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] assets: loader app/view app/
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] assets script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-05-06T01_40_37_539Z-debug.log
目前前端代码(app/public
) 部分是 ignore 了。
要开启下,在 app/public/.eslintrc
里面继承 eslint-config-egg
定制一些规则即可
为什么clone下项目,运行npm run start 的时候 ,页面 js 和 css 没有加载进来,是我缺少了什么步骤吗 (npm run dev 没问题 页面是正常的 ,已经运行了 npm run assets
同时生成了 assets.json ,代码方面只修改了 redis mongo
配置 )
在输入错误的用户名和密码进行登录的时候,没有相应的提示信息。
之前是有错误提示的
发布话题的时候如果不输入标题或内容点击提交的时候 报422的错误。原来是在页面上直接有提示。
写了一套UI自动化测试的代码 https://github.com/CnodejsTest/UIAutoTest
我的cnodejs账号是直接通过github登录的,之前因为清理github的项目问题,直接把github账号删除了,然后重新建立了一个新的github账号,名称跟以前一样,但是现在登录cnodejs的时候,没办法关联上了,就登录不了用户了。
浏览器中地址
http://egg.cnodejs.org/passport/github/callback?code=8aaae50ef8bb8c167f6e
返回错误提示:
Internal Server Error, real status: 500
config.passportGithub = {
key: process.env.EGG_PASSPORT_GITHUB_CLIENT_ID,
secret: process.env.EGG_PASSPORT_GITHUB_CLIENT_SECRET,
callbackURL: 'https://eosdevs.io/passport/github/callback',
};
这里保证key
和secret
没有问题, callbackURL
在github中配置如下:
即https://eosdevs.io/passport/github/callback
,
但是线上项目https://eosdevs.io
的使用github登陆总是提示redirect_uri_mismatch
。
经过抓包发现,
期望能得到解答。
// old
const title = validator.trim(ctx.body.title);
const tab = validator.trim(ctx.body.tab);
const content = validator.trim(ctx.body.t_content);
let editError;
if (title === '') {
editError = '标题不能是空的。';
} else if (title.length < 5 || title.length > 100) {
editError = '标题字数太多或太少。';
} else if (content === '') {
editError = '内容不可为空';
}
// egg-validate
const RULE_CREATE = {
title: {
type: 'string',
required: true,
max: 100,
min: 5,
},
content: {
type: 'string',
required: true,
},
};
class TemplateController extends Controller {
async create() {
const { ctx } = this;
ctx.logger.debug(ctx.request.body);
ctx.validate(RULE_CREATE, ctx.request.body);
// ...
}
}
Of course with ssr support.
现在的 cnodejs.org 每页显示是40个帖子,新版这边为什么改成20个了?
40个帖子比较能够对齐右边栏,20个的时候左侧有较大空白区域。
已经修复的问题,新用户 accessToken 的生成逻辑完善。空白 accessToken 用户通过 bin/generate_access_token.js
来补充。
鉴于以上问题都挺严重的,建议回滚老版本。
问题2的github登录问题,我尝试了几个方式,都没法拿到 githubHandler 中的错误信息,导致外层没数据作出正确响应。这个 passport 库的封装挺神奇的。本来 passport.js 是为 express 那套中间件所写,eggjs在上面包了一层逻辑,不过对于错误的抛出应该给出更明确的指导。
登录出现异常
cnode的egg公测帖子上有一个关于添加站内搜索的反馈
大家看是否要支持一下这个需求?
我的想法是分三个主要搜索选项:
里面可能涉及新页面设计, 风格上当然保持和原有一致.
大家觉得怎么样?
在使用公众号发文章的时候,可以复制文本+图片 直接粘贴到编辑区,图片会适配的很好。我们社区能否改进一下图片编辑,特别是分享的时候可以复制粘贴方便些。
需要调用数据库的操作。
在 CNode 中,增加一些 Egg.js 相关的文案。
我看controller 里面就在上传七牛云里面用到了 try catch
Internal Server Error, real status: 500
开启 redis 和mongo 默认端口设置 6379 和 27017
redis:
image: redis:3.2-alpine
command: redis-server --appendonly yes --requirepass egg_cnode
volumes:
- egg-redis:/data
networks:
- docker_cnode
ports:
- 6379:6379
mongodb:
image: mongo:3.2
restart: always
environment:
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=mongodb
- MONGO_INITDB_DATABASE=egg_cnode
volumes:
- egg-mongo:/data/db
- ./init.d/mongo:/docker-entrypoint-initdb.d
networks:
- docker_cnode
ports:
- 27017:27017
[root@VM_0_11_centos egg-cnode]# docker-compose up -d
Creating network "eggcnode_docker_cnode" with driver "bridge"
Creating volume "eggcnode_egg-mongo" with default driver
Creating volume "eggcnode_egg-redis" with default driver
Creating eggcnode_mongodb_1 ... done
Creating eggcnode_redis_1 ... done
Creating eggcnode_cnode_1 ... done
2018-04-08 07:07:18,978 INFO 42 [egg:core:ready_stat] end ready task /usr/src/app/node_modules/egg-core/lib/egg.js:319:10, remain ["/usr/src/app/node_modules/egg-watcher/app.js:15:7","/usr/src/app/node_modules/egg-redis/lib/redis.js:48:7","/usr/src/app/node_modules/egg-mongoose/lib/mongoose.js:74:7"]
2018-04-08 07:07:18,985 ERROR 42 [egg-mongoose] mongodb://egg_cnode:egg_cnode@mongodb:27017/egg_cnode disconnected
2018-04-08 07:07:18,987 INFO 42 [egg-redis] connect success on redis://:egg_cnode@redis:6379/0
2018-04-08 07:07:18,991 ERROR 42 nodejs.MongoError: [egg-mongoose]failed to connect to server [mongodb:27017] on first connect [MongoError: connect ECONNREFUSED 172.19.0.2:27017]
at Pool.<anonymous> (/usr/src/app/node_modules/mongodb-core/lib/topologies/server.js:336:35)
at emitOne (events.js:116:13)
at Pool.emit (events.js:211:7)
at Connection.<anonymous> (/usr/src/app/node_modules/mongodb-core/lib/connection/pool.js:280:12)
at Object.onceWrapper (events.js:317:30)
at emitTwo (events.js:126:13)
at Connection.emit (events.js:214:7)
at Socket.<anonymous> (/usr/src/app/node_modules/mongodb-core/lib/connection/connection.js:189:49)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at emitErrorNT (internal/streams/destroy.js:64:8)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
name: 'MongoError'
message: '[egg-mongoose]failed to connect to server [mongodb:27017] on first connect [MongoError: connect ECONNREFUSED 172.19.0.2:27017]'
pid: 42
hostname: ee66c1c8cd4f
[root@VM_0_11_centos egg-cnode]# mongo 172.19.0.2:27017/egg_cnode -u egg_cnode -p egg_cnode
MongoDB shell version: 3.2.19
connecting to: 172.19.0.2:27017/egg_cnode
> show collections
egg_cnode
> db.egg_cnode.find({})
{ "_id" : ObjectId("5ac9bfa4cdf6538a02662544"), "egg_cnode" : "egg-cnode" }
在centos 中可以正常访问 172.19.0.2:27017/egg_cnode 库
本人 docker 和 docker-compose 知识有限,目前使用遇到如上问题,还望大神帮忙答疑解惑
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.