Code Monkey home page Code Monkey logo

tiny-engine-webservice's Introduction

OpenTiny Logo

Tiny Engine Web Service is a RESTful API responsible for providing data services, code generation services, and code release services to the front end. It does not directly operate on the database, and data operations request interfaces from TinyEngine Data Center.

English | 简体中文

Directory Rules

Before development, you need to understand the overall directory structure of the project and compile code according to the following rules

├── README.md
├── app
│   ├── controller                      // controller
│   │   └── service controller                    // Create a service folder for a specific service. For a public service, name the folder common
│   │       ├── api.js                  // api file processes interface-related logic
│   │       └── page.js                 // page file mainly processes the page logic
│   ├── extend
│   │   └── helper.js                   //  controller can be extracted to the helper and referenced by this.ctx.helper.xxx
│   ├── middleware                      // This part of middleware must be public logic. (For multi-language processing, remember to distinguish between JSON and HTML.) The service logic is not stored in the middleware. The common processing logic can be defined in the helper based on the service space
│   ├── public                          // Static file directory. Resources in the directory can be accessed in /public/ mode during local development. However, you need to configure the /public/ permission at the gateway layer on the release line. (It is recommended that static resources be stored in CDN.)
│   │   └── Static resource of the service                // The static directory also needs to distinguish specific service types by folder. Here, doc is the service of the document center, and the Zhishi folder is created in the knowledge base
│   │       ├── css
│   │       ├── images
│   │       └── js
│   ├── router                          // Routes are divided based on services. All routes must have their own service prefixes. Other services except common services do not use the / * global route. Instead, the / service name / * route is used to process the logic of their own services
│   │   ├── common.js                   // The common JS is used to process routing under the root directory /*. Other service logic cannot be placed in the common JS
│   │   └── Service route.js
│   ├── service                         // The service is the same as the controller. The service is divided based on the service
│   │   └── Service-related backend interface services         // Interfaces used for interconnection with the backend are classified based on services
│   │       └──Interface logic of the specific service on which the service depends.js
│   └── view                            // The view stores the ejs template. The file directory is divided based on the service. (Divide different templates according to the language directory under the service) , where common and error are common layout and error handling respectively
│       ├── common                      // Common stores public layout files (such as header, footer, and sidecar). Each service can include the files to its own service as required.
│       │   ├── en-us                   // Template for public English
│       │   │   └── index.tpl
│       │   └── zh-cn                   // Public Chinese Template
│       │       ├── footer.tpl
│       │       └── header.tpl
│       ├── Service template                // Service template of the document center
│       │   ├── en-us
│       │   │   └── index.tpl
│       │   └── zh-cn
│       │       ├── 404.html
│       │       ├── content
│       │       │   ├── catalog.tpl
│       │       │   └── content.tpl
│       │       └── pages.tpl
│       └── error                        // he error directory stores error processing files. For example, errors such as 404 500 can be placed in the directory and are divided by language
│           ├── en-us
│           │   └── 404.tpl
│           └── zh-cn
│               └── 404.tpl
├── config                               // Different project configurations are loaded based on different environments
│   ├── config.default.js                // This file is the default configuration file. After being defined in other config files, the file will be combined in Object.assig(config.defalut.js, config.xxxx.js) mode based on the environment. Therefore, all common configurations of different environments are combined here, and other configurations can be customized
│   ├── config.local.js                  // You only need to configure local differentiated configurations
│   ├── config.prod.js
│   └── plugin.js                       // Plug-in switch directory. You can switch plug-ins based on the site requirements
├── logs                                // Output directory of local development logs
├── package.json
├── test                                // Compile test cases in BDD mode
│   └── Service Test Cases                      // Service-related test cases
│        ├── controller.test.js         // Test by language/Test by whether the interface is 200
│        └── service.test.js            // Use the assert assertion library to test whether the interface returned by the service is normal
└── typings                             // Egg uses the typescript to temporarily generate some definition files, which can be ignored during routine development

Interface Return Specifications

1.Return Format
  • Correct data
{
    "locale": "zh-cn",
    "data": {
      "app": {
        "count": 100
      }
    }
}
  • Error Data
{
    "locale": "zh-cn",
    "data": {},
    "error": {
      "code": "CM002",
      "message": "name 不能为空",
    }
}
2.How to Ensure the Accuracy of Error Codes and Error Information
  • The Egg interface is normal. The HTTP status code is 200 except that the service layer returns 403 for re-login. The exception cause is error.
  • Entry internationalization: The corresponding error code and entry content are continuously added to the config/locale file.
  • Do not request the data-center interface and directly invoke helper.commonJson() to return data.
  • Request the interface of the data center:
// Invoke the corresponding service method to initiate a query request. The dataService invokes helper.getResponseData().
// getResponseData: normalizes and converts the error information returned by the data center.
const createRes = await platforms.createPlatform(body);
// If the common error message does not contain the field, reprocess the obtained data.
// The formatResponse can be logically extended.
this.ctx.body = this.ctx.helper.formatResponse(createRes, 'name');
3.Parameter field validation
  • Use validate to verify the field necessity and format at the egg service layer interface to prevent this error from being thrown in the strapi. If there are special requirements on the data format, add rules in app/validate.
4.error-handling middleware
  • Add error interception processing to the middleware errorResponse.ts. Exceptions caused by the server will be captured and 500 will be returned. Exceptions thrown by other middleware will be added based on the error content.

Instruction Manual

For specific server usage documentation, please see TinyEngine Official Website - User Manual

development

Environment Variables

Variable name Description
GIT_USERNAME Code repository user name with push code permission when the application is published
GIT_EMAIL The email address of the user who has push code permissions in the code repository when the application is published
GIT_USER_TOKEN Code repository token with push code permission when the application is published
GIT_REPO Code repository address when the application is released
GIT_BRANCH The branch where the code is submitted by default when the application is released
DATA_CENTER_URL Data center address, for example:https://www.mydatacenter.com
PROXY_SERVER Selective setting. If your server requires proxy services to access external data, you need to configure the address of the proxy service
OPENAI_API_KEY API key for openai AI interface
WENXIN_ ACCESS_ TOKEN Access to the AI interface ERNIE Bot_ token (updated every 30 days)
NPM_AUTH_TOKEN The authToken of npmjs.com users with publish permission, which is used to publish blocks

The following are the configuration items for reference environment variables: obs configuration This open source code provides usage examples for pairing with Huawei Cloud OBS:

Variable name Description
OBS_AK obs AK This sample code uses Huawei Cloud obs. If you use other cloud service products, please search for relevant code modification logic to adapt it.
OBS_SK obs SK This sample code uses Huawei Cloud obs. If you use other cloud service products, please search for relevant code modification logic to adapt it.
OBS_ACCESS_URL obs resource access url, for example:https://tinyengine.obs.cn-north-4.myhuaweicloud.com/somepath/somefile.tar.gz
OBS_SERVICE_URL The obs service link parameter passed in when using the obs sdk, for example:https://obs.cn-north-4.myhuaweicloud.com

RabbitMQ configuration

This open source code provides an example of using RabbitMQ to connect to a task queue (the RabbitMQ plugin in the open source code is turned off. If necessary, please turn it on. Also restore the commented code in app.ts in the project root directory):

Variable name Description
MQ_IP The IP address of the task queue service
MQ_PORT The task queue service port, for example, 5671
MQ_USERNAME Task queue service user name
MQ_PASSWORD Task queue service password

If CI/CD deployment or containerized deployment of your own service is involved, please configure environment variables according to the characteristics of your own product and tool based on the above list;

Local Runtime Configuration Method:

git-bash or bash

vi ~/.bashrc
export MQ_IP=192.168.0.11
export MQ_PORT=5671
# Wait for environment variables

After setting, reopen the command line or execute it in the current command line

source ~/.bashrc

Make the set environment variables take effect;(The environment variables set in git bash cannot be applied to powershell and cmd) Start project nodejs version selection: >= 16 Go to the root directory of the project and execute it once:

yarn install --ignore-engines
npm run dev

Milestones

gantt 
dateFormat YYYY-MM-DD
axisFormat %Y-%m-%d

	1.0.0-beta.x version	:active,2023-09-25, 2024-03-31
	1.0.0-rc	version    :       2024-04-01, 2024-06-30
	1.0.0 version   :          2024-07-01, 2024-07-31

Loading

🤝 Participating in contributions

If you are interested in our open source project, please join us!

Please read the Contribution Guide (CONTRIBUTING.zh-CN.md) before participating in the contribution.

  • Add official assistant WeChat opentiny-official and join the technical exchange group
  • Join the mailing list [email protected]

Open source protocol

MIT

tiny-engine-webservice's People

Contributors

chilingling avatar fleurxxx avatar gene9831 avatar h-ivy avatar lu-yg avatar m8989 avatar wenmine 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tiny-engine-webservice's Issues

🐛 [Bug]: 同步物料时未校验JSON,导致无法parse的JSON入库

Environment

Chrome 版本 122.0.6261.129(正式版本) (64 位)

Version

v16.20.2

Version

@opentiny/[email protected]

Link to minimal reproduction

最新

Step to reproduce

  1. 新增一个组件物料
  2. 执行 pnpm buildMaterials
  3. 提示新增成功,查看数据库已入库

但是刷新页面后,提示服务器500,查看是data-center报了错,有个物料JSON无法parse成功
[2024-03-28T11:17:34.667Z] debug GET /apps/918 (119 ms) 200
[2024-03-28T11:17:34.698Z] error SyntaxError: Expected ',' or '}' after property value in JSON at position 1257
SyntaxError: Expected ',' or '}' after property value in JSON at position 1257
at JSON.parse ()

检查数据库中新增的物料,确实无法parse,删除物料后刷新页面正常进入

建议入库前做个JSON校验

What is expected

No response

What is actually happening

No response

Any additional comments (optional)

No response

🐛 [Bug]: dslGenerate(schema, componentsMap); 包含无用代码 import { p, span } from 'undefined'

Environment

chrome

Version

18.17.0

Version

latest

Link to minimal reproduction

dslGenerate(schema, componentsMap);

Step to reproduce

schema:
{
"state": {},
"methods": {},
"componentName": "Page",
"css": ".page-vvhvn {\n color: #666666;\n margin: 0 10px;\n margin-top: 30px;\n}\n.page-vvhvn p {\n margin: 20px 0;\n font-size: 16px;\n}\n.page-vvhvn .bold,\np span {\n font-weight: bold;\n}\n",
"props": {
"className": "page-vvhvn"
},
"lifeCycles": {},
"children": [
{
"componentName": "GlobalHeader",
"props": {
"title": "123"
},
"children": [
{
"componentName": "Text",
"props": {
"text": "次级导航头"
}
}
],
"id": "b46d2629"
},
{
"componentName": "p",
"props": {},
"children": "活动期间,下载并安装“APP”\n,进入APP首页后,找到活动入口,点击进入后即可参加活动,具体规则如下:",
"id": "5243c744"
},
{
"componentName": "div",
"props": {},
"id": "66643684",
"children": [
{
"componentName": "Text",
"props": {
"text": " 本次818理财节活动时间为 "
},
"id": "42252454"
},
{
"componentName": "Text",
"props": {
"text": " 2022年8月15日-2022年8月26日",
"className": "bold"
},
"id": "44f64635"
}
]
},
{
"componentName": "p",
"props": {},
"children": " 1.做任务获得积分红包赢取转盘抽奖,集满50分即可获得一次转盘抽奖机会。新用户请用注册手机号开户并使用开立的资金账号才能获取活动的积分红包,已完成任务的用户可直接领取对应积分红包,其中,邀请好友参与转盘活动,被邀请人需要满足之前未参与过该活动,才能获得对应积分。\n",
"id": "f96365f2"
},
{
"componentName": "p",
"props": {},
"children": "2.定时财富红包:每天登陆即领积分,时间段为9:00-9:30,13:00-13:30,每个时间段最多只能领取一次。财富值范围5-10分随机。\n",
"id": "7da56d45"
},
{
"componentName": "p",
"props": {},
"children": "3.奖励领取规则:抽中福利理财产品(6.18%收益凭证、6.66%报价回购)购买资格限当天使用,过期未使用则作废,产品可能提前售罄无法购买成功。抽中折扣优惠券无使用时间限制,其中“投顾福利折扣”可叠加使用,“申购一折”不可叠加,可重复使用;抽中答题赢幸运福袋、礼包机会在答对问题后三个工作日内联系所在营业部留下寄送地址,过期视为放弃领奖。\n",
"id": "26345235"
},
{
"componentName": "p",
"props": {},
"children": "*答题赢礼包内容为随机抽取,请以页面提示为准。",
"id": "53634d65"
}
],
"dataSource": {
"list": []
},
"utils": [],
"bridge": [],
"inputs": [],
"outputs": [],
"fileName": "Rule"
}

componentsMap:
[
{ componentName: 'a', main: 'components' },
{ componentName: 'button', main: 'components' },
{ componentName: 'form', main: 'components' },
{ componentName: 'h1,h2,h3,h4,h5,h6', main: 'components' },
{ componentName: 'Img', main: 'components' },
{ componentName: 'input', main: 'components' },
{ componentName: 'label', main: 'components' },
{ componentName: 'p', main: 'components' },
{ componentName: 'table', main: 'components' },
{ componentName: 'td', main: 'components' },
{ componentName: 'video', main: 'components' },
{ componentName: 'span', main: 'components' },
{
componentName: 'TinyForm',
package: '@opentiny/vue',
exportName: 'Form',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyFormItem',
package: '@opentiny/vue',
exportName: 'FormItem',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyButton',
package: '@opentiny/vue',
exportName: 'Button',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyInput',
package: '@opentiny/vue',
exportName: 'Button',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinySwitch',
package: '@opentiny/vue',
exportName: 'Switch',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyRadio',
package: '@opentiny/vue',
exportName: 'Radio',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyRow',
package: '@opentiny/vue',
exportName: 'Row',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyPopover',
package: '@opentiny/vue',
exportName: 'Popover',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyTooltip',
package: '@opentiny/vue',
exportName: 'Tooltip',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyTimeLine',
package: '@opentiny/vue',
exportName: 'TimeLine',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyTree',
package: '@opentiny/vue',
exportName: 'Tree',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyPopeditor',
package: '@opentiny/vue',
exportName: 'Popeditor',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyPager',
package: '@opentiny/vue',
exportName: 'Pager',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyCol',
package: '@opentiny/vue',
exportName: 'Col',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyGrid',
package: '@opentiny/vue',
exportName: 'Grid',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinySelect',
package: '@opentiny/vue',
exportName: 'Select',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinySearch',
package: '@opentiny/vue',
exportName: 'Search',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyCheckbox',
package: '@opentiny/vue',
exportName: 'Checkbox',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyDialogBox',
package: '@opentiny/vue',
exportName: 'DialogBox',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyTabs',
package: '@opentiny/vue',
exportName: 'Tabs',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyTabItem',
package: '@opentiny/vue',
exportName: 'TabItem',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyCollapse',
package: '@opentiny/vue',
exportName: 'Collapse',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyCollapseItem',
package: '@opentiny/vue',
exportName: 'CollapseItem',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyCheckboxButton',
package: '@opentiny/vue',
exportName: 'CheckboxButton',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyCheckboxGroup',
package: '@opentiny/vue',
exportName: 'CheckboxGroup',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyCarousel',
package: '@opentiny/vue',
exportName: 'Carousel',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'TinyCarouselItem',
package: '@opentiny/vue',
exportName: 'CarouselItem',
destructuring: true,
version: '3.11.2'
},
{
componentName: 'ElButton',
package: 'element-plus',
exportName: 'ElButton',
destructuring: undefined,
version: '2.4.2'
},
{
componentName: 'ElForm',
package: 'element-plus',
exportName: 'ElForm',
destructuring: undefined,
version: '2.4.2'
},
{
componentName: 'ElFormItem',
package: 'element-plus',
exportName: 'ElFormItem',
destructuring: undefined,
version: '2.4.2'
},
{
componentName: 'ElInput',
package: 'element-plus',
exportName: 'ElInput',
destructuring: undefined,
version: '2.4.2'
},
{
componentName: 'ElTable',
package: 'element-plus',
exportName: 'ElTable',
destructuring: undefined,
version: '2.4.2'
},
{
componentName: 'ElTableColumn',
package: 'element-plus',
exportName: 'ElTableColumn',
destructuring: undefined,
version: '2.4.2'
},
{
componentName: 'TinyBreadcrumb',
package: '@opentiny/vue',
exportName: 'Select',
destructuring: true,
version: ''
},
{
componentName: 'TinyBreadcrumbItem',
package: '@opentiny/vue',
exportName: 'BreadcrumbItem',
destructuring: true,
version: ''
},
{
componentName: 'TinyButtonGroup',
package: '@opentiny/vue',
exportName: 'ButtonGroup',
destructuring: true,
version: ''
},
{
componentName: 'MuHeader',
package: 'mumu2-ui',
exportName: 'Header',
destructuring: undefined,
version: '0.3.0'
},
{
componentName: 'mu-header',
package: 'mumu2-ui',
exportName: 'mu-header',
destructuring: undefined,
version: '0.1.0'
},
{
componentName: 'Header',
package: 'ms-ui-lib',
exportName: 'MsHeader',
destructuring: undefined,
version: '0.1.0'
},
{
componentName: 'MsHeader',
package: 'ms-ui-lib',
exportName: 'Header',
destructuring: undefined,
version: '0.8.4'
},
{
componentName: 'BigWheel',
package: 'ms-ui-lib',
exportName: 'BigWheel',
destructuring: undefined,
version: '0.8.8'
},
{
componentName: 'Marquee',
package: 'ms-ui-lib',
exportName: 'Marquee',
destructuring: undefined,
version: '0.8.1'
},
{
componentName: 'NineSquare',
package: 'ms-ui-lib',
exportName: 'NineSquare',
destructuring: undefined,
version: '0.8.2'
},
{
componentName: 'SlotMachine',
package: 'ms-ui-lib',
exportName: 'SlotMachine',
destructuring: undefined,
version: '0.8.2'
},
{
componentName: 'Launch',
package: 'ms-ui-lib',
exportName: 'MsLaunch',
destructuring: undefined,
version: '0.6.0'
},
{
componentName: 'ScoreTaskList',
package: 'ms-ui-lib',
exportName: 'ScoreTaskList',
destructuring: undefined,
version: '0.8.2'
},
{
componentName: 'MsLaunch',
package: 'ms-ui-lib',
exportName: 'Launch',
destructuring: undefined,
version: '0.8.1'
},
{
componentName: 'GlobalHeader',
package: 'ms-ui-lib',
exportName: 'GlobalHeader',
destructuring: undefined,
version: '0.8.2'
},
{
componentName: 'CredentialAward',
package: 'ms-ui-lib',
exportName: 'CredentialAward',
destructuring: undefined,
version: '0.8.1'
},
{
componentName: 'EtfHot',
package: 'ms-ui-lib',
exportName: 'EtfHot',
destructuring: undefined,
version: '0.8.2'
},
{ componentName: 'MyAward', main: 'views' },
{ componentName: 'Index', main: 'views' },
{ componentName: 'Rule', main: 'views' }
]

What is expected

No response

What is actually happening

No response

Any additional comments (optional)

No response

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.