Coder Social home page Coder Social logo

artpieces-back-end's Introduction

Artpieces-Backend/GraphQL

计算机和画画有许多共同之处。事实上,在我所知道的所有行业中,黑客与画家最像。

黑客与画家的共同之处,在于他们都是创作者。与作曲家、建筑师、作家一样,黑客和画家都是试图创作出优秀的作品。他们本质上都不是在做研究,虽然在创作的过程中,他们可能会发现一些新技术(当然那样更好)。——《黑客与画家》


这仅是参赛使用的Demo,之后会考虑使用 TypeScript 重写,加入 JWT,并且使用 Egg.js 将两个 server 整合。

前端地址

GraphQL Playground / API 测试地址(https://artpieces.cn/api)

注意:一定要在地址栏加上/api,如图所示,否则将没有任何结果。 截图

Upload server 地址:https://artpieces.cn/img

Convention

Mutation类型的 API 将统一返回Msg对象,这个对象的结构是:

{
    "status": Number,
    "payload": Object
}

status0时表示正常返回,这时payload的类型取决于 API 的类型,在 API 文档里有清晰的说明(在 Playground 里,用Status-0-Payload来指代这个对象的);

status不为0时表示有错误发生,这时payload是一个说明错误原因的String。目前支持的错误类型有:

status payload description
-1 Access Denied: wrong password. 用户密码错误
-2 Access Denied: illegal identity. 用户身份不符合,试图改动他人数据
-3 Object Not Found 数据操作目标不存在
-4 The target is already in the database! 插入目标在数据库中已存在
1 ? 其他类型错误,payload 不确定

Structure

Artpieces Backend
    |-- api_server/             // API 服务器
    |   |-- src/                // 源代码
    |   |   |-- app.js          // 主程序入口
    |   |   |-- controller.js   // API 函数
    |   |   |-- misc.js         // 一个使得服务器更安全启动的模块
    |   |   |-- model.js        // 数据库模型(数据包定义)
    |   |   `-- schema.graphql  // GraphQL Schema
    |   `-- dist/               // Babel 编译后的代码
    |
    `-- upload_server/          // 文件(图片)上传服务器
        |-- app.js              // 主程序入口
        `-- index.html          // 供测试用的网页

TODOs

  • 用户注册限制(目前用户注册 API 没有任何限制,可以非法注册大量用户)
  • 身份验证
  • 完善的错误处理系统
  • 完善的测试系统
  • 旧图片的自动销毁
  • 信息流推送系统

RESTful 移植版

Checkout to branch restful.

artpieces-back-end's People

Contributors

atomicvar avatar

Stargazers

 avatar

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.