Crowi 开源项目教程

Crowi 开源项目教程

crowiCrowi – The Markdown Wiki – Empower the team with sharing your knowledge项目地址:https://gitcode.com/gh_mirrors/cr/crowi

1. 项目的目录结构及介绍

Crowi 项目的目录结构如下:

  1. crowi/

  2. ├── app/

  3. │ ├── auth/

  4. │ ├── models/

  5. │ ├── routes/

  6. │ ├── utils/

  7. │ └── views/

  8. ├── config/

  9. │ ├── env/

  10. │ ├── initializers/

  11. │ └── production.js

  12. ├── lib/

  13. │ ├── api/

  14. │ ├── service/

  15. │ └── util/

  16. ├── public/

  17. │ ├── fonts/

  18. │ ├── images/

  19. │ ├── js/

  20. │ └── stylesheets/

  21. ├── scripts/

  22. │ ├── docker/

  23. │ ├── init/

  24. │ └── update/

  25. ├── test/

  26. │ ├── fixtures/

  27. │ ├── integration/

  28. │ ├── unit/

  29. │ └── utils/

  30. ├── .babelrc

  31. ├── .dockerignore

  32. ├── .editorconfig

  33. ├── .env.example

  34. ├── .eslintrc

  35. ├── .gitignore

  36. ├── .npmrc

  37. ├── .travis.yml

  38. ├── Dockerfile

  39. ├── LICENSE

  40. ├── README.md

  41. ├── app.js

  42. ├── package.json

  43. └── yarn.lock

目录介绍

  • app/: 包含应用程序的主要代码,如认证、模型、路由和视图。
  • config/: 包含配置文件,如环境配置和初始化文件。
  • lib/: 包含API、服务和工具函数。
  • public/: 包含静态资源,如字体、图像、JavaScript和样式表。
  • scripts/: 包含用于Docker、初始化和更新的脚本。
  • test/: 包含单元测试、集成测试和测试工具。
  • 根目录下的文件包括配置文件、Dockerfile、许可证、README.md、主应用程序文件和包管理文件。

2. 项目的启动文件介绍

Crowi 项目的主启动文件是 app.js。这个文件负责初始化应用程序并启动服务器。以下是 app.js 的主要内容:

  1. const express = require('express');

  2. const path = require('path');

  3. const logger = require('morgan');

  4. const cookieParser = require('cookie-parser');

  5. const bodyParser = require('body-parser');

  6. const mongoose = require('mongoose');

  7. const config = require('./config');

  8. const app = express();

  9. // 配置视图引擎

  10. app.set('views', path.join(__dirname, 'app/views'));

  11. app.set('view engine', 'jade');

  12. // 使用中间件

  13. app.use(logger('dev'));

  14. app.use(bodyParser.json());

  15. app.use(bodyParser.urlencoded({ extended: false }));

  16. app.use(cookieParser());

  17. app.use(express.static(path.join(__dirname, 'public')));

  18. // 连接数据库

  19. mongoose.connect(config.db.uri, config.db.options);

  20. // 加载路由

  21. require('./app/routes')(app);

  22. // 捕获404并转发到错误处理程序

  23. app.use((req, res, next) => {

  24. const err = new Error('Not Found');

  25. err.status = 404;

  26. next(err);

  27. });

  28. // 错误处理程序

  29. app.use((err, req, res, next) => {

  30. res.status(err.status || 500);

  31. res.render('error', {

  32. message: err.message,

  33. error: app.get('env') === 'development' ? err : {}

  34. });

  35. });

  36. module.exports = app;

启动文件介绍

  • app.js 初始化 Express 应用程序,配置视图引擎和中间件。
  • 连接到 MongoDB 数据库。
  • 加载应用程序的路由。
  • 处理404错误和通用错误。

3. 项目的配置文件介绍

Crowi 项目的配置文件主要位于 config/ 目录下。以下是主要的配置文件:

config/env/

这个目录包含不同环境的配置文件,如 development.jsproduction.jstest.js。每个文件定义了特定环境的配置参数。

config/initializers/

这个目录包含初始化文件,如 passport.jssession.js,用于配置 Passport 认证和会话管理。

config/production.js

crowiCrowi – The Markdown Wiki – Empower the team with sharing your knowledge项目地址:https://gitcode.com/gh_mirrors/cr/crowi

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...