Giter Site home page Giter Site logo

fomenyesu / egg-restapi-module-tool Goto Github PK

View Code? Open in Web Editor NEW
339.0 16.0 58.0 1.38 MB

a example of eggjs, react, antd, dva, webpack, mysql, restful api and other stuff made it work...

JavaScript 26.42% CSS 73.33% HTML 0.25%
egg-restapi-module-tool egg-rest egg-restapi egg dva react

egg-restapi-module-tool's Introduction

Egg Restapi Module Tool

a example of eggjs2.0, react, antd, dva2.0, webpack, mysql, restful api and other stuff made it work...

you can generate rest api eazily by this tool.

中文 README

update note:

2017-07-10 initial

2017-12-01 update login module with oauth2.0

2018-01-03 update dva to dva2.0

2018-01-04 update egg to egg2.0

Examples for egg

use react, Antd and dva to develop front end modules. use eggjs and mysql to be backend. you can use npm run dev to develop both side's service. or use it as a boilerplate.

this example include two modules: 1 modules manager : module table's CRUD operation, 2 request manager : an note for restful api witch is generated by module tool.

Develop

Installation

install mysql start mysql import testdb.sql to mysql

npm i egg-bin --save-dev
npm install

Start up:

run npm to start server

npm run dev

Go to http://localhost:8080

also you can : npm run dev_static to start front react project npm run server to start egg server npm run dev to start both

Distribute

$ npm run build
$ npm run pro

npm run build to build the front end react project. npm run pro in server to start project on you server visit http://serverIP:7001

REST API Example

api/restql/users GET List

{
"meta":{"total":3},
"data":[
{"_id":"58d8a899f5f2486f1f6d4236","uid":1,"name":"admin","pass":"123","status":1,"time":"1325472736"},
{"_id":"58db7828a14b14815447cf33","name":"sdf","pass":"123","status":1,"time":"1325472736","uid":3,"__v":0},
{"_id":"58db7d3bcee4d48df6f5bdfd","name":"sdddf","pass":"123","status":1,"time":"1325472736","uid":4,"__v":0}
]
}

api/restql/users/1 GET Single Data

{
"meta":{"total":1},
"data":[
{"_id":"58d8a899f5f2486f1f6d4236","uid":1,"name":"admin","pass":"123","status":1,"time":"1325472736"}
]
}

api/restql/users/2 PUT Update data with uid

{"name":"admin123","pass":"123","status":1,"time":"1325472736"}

api/restql/users POST insert data

{"name":"admin123","pass":"123","status":1,"time":"1325472736"}

same with news and news_type for rest api data.

screen shot

login.png page1.png page2.png page3.png

Thank you

egg

ant-design

antd-admin

egg-restapi-module-tool's People

Contributors

fomenyesu 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

egg-restapi-module-tool's Issues

关于数据库配置与使用

我打算运行该项目,按您的说明,可以正常运行,但数据库不存在,页面无法正常工作,是否可以添加对数据库使用的说明,首次使用,后面如需要改动结构该如何处理?

端口问题

请问 怎么设置里面的端口问题 我有两个项目 感觉好像都是8000就会冲突只显示一个项目 求教

Failed to load resource: net::ERR_CONNECTION_TIMED_OUT

运行项目,填写用户名密码,一直显示加载用户信息,打开控制台发现很多这样的报错:
Failed to load resource:
net::ERR_CONNECTION_TIMED_OUT
Error: Network Error
at e.exports (index.js:6)
at XMLHttpRequest.p.onerror (index.js:6)
请问该怎么解决?

启动后登陆后台提示 Unauthorized request: no authentication given

刚接触 egg 和 react,
用这个项目学习,
点击登录(账号密码默认的 admin 和 123 )提示 Unauthorized request: no authentication given 这个错误,
能帮我解答是哪里不对吗
详细的日志:

2018-09-26 17:06:40,958 WARN 42221 [-/127.0.0.1/-/18ms POST /user/authorize?t=1537952800909] nodejs.unauthorized_request: Unauthorized request: no authentication given
    at new UnauthorizedRequestError (/Users/wangql/src/egg-restapi-module-tool/node_modules/oauth2-server/lib/errors/unauthorized-request-error.js:28:14)
    at AuthenticateHandler.getTokenFromRequest (/Users/wangql/src/egg-restapi-module-tool/node_modules/oauth2-server/lib/handlers/authenticate-handler.js:132:9)
    at AuthenticateHandler.<anonymous> (/Users/wangql/src/egg-restapi-module-tool/node_modules/oauth2-server/lib/handlers/authenticate-handler.js:68:19)
    at runCallback (timers.js:810:20)
    at tryOnImmediate (timers.js:768:5)
    at processImmediate [as _immediateCallback] (timers.js:745:5)
From previous event:
    at AuthenticateHandler.handle (/Users/wangql/src/egg-restapi-module-tool/node_modules/oauth2-server/lib/handlers/authenticate-handler.js:67:6)
    at OAuth2Server.authenticate (/Users/wangql/src/egg-restapi-module-tool/node_modules/oauth2-server/lib/server.js:43:6)
    at OAuth2.execute (/Users/wangql/src/egg-restapi-module-tool/node_modules/egg-oauth2-server/lib/server.js:86:41)
    at /Users/wangql/src/egg-restapi-module-tool/node_modules/egg-oauth2-server/lib/server.js:108:32
    at dispatch (/Users/wangql/src/egg-restapi-module-tool/node_modules/koa-router/node_modules/koa-compose/index.js:44:32)
    at next (/Users/wangql/src/egg-restapi-module-tool/node_modules/koa-router/node_modules/koa-compose/index.js:45:18)
    at /Users/wangql/src/egg-restapi-module-tool/node_modules/koa-router/lib/router.js:346:16
    at dispatch (/Users/wangql/src/egg-restapi-module-tool/node_modules/koa-router/node_modules/koa-compose/index.js:44:32)
    at /Users/wangql/src/egg-restapi-module-tool/node_modules/koa-router/node_modules/koa-compose/index.js:36:12
    at dispatch (/Users/wangql/src/egg-restapi-module-tool/node_modules/koa-router/lib/router.js:351:31)
    at dispatch (/Users/wangql/src/egg-restapi-module-tool/node_modules/koa-compose/index.js:42:32)
    at createGenerator (/Users/wangql/src/egg-restapi-module-tool/node_modules/koa-convert/index.js:24:16)
    at createGenerator.next (<anonymous>)
    at onFulfilled (/Users/wangql/src/egg-restapi-module-tool/node_modules/co/index.js:65:19)
    at /Users/wangql/src/egg-restapi-module-tool/node_modules/co/index.js:54:5
    at new Promise (<anonymous>)
    at Object.co (/Users/wangql/src/egg-restapi-module-tool/node_modules/co/index.js:50:10)
    at Object.toPromise (/Users/wangql/src/egg-restapi-module-tool/node_modules/co/index.js:118:63)
    at next (/Users/wangql/src/egg-restapi-module-tool/node_modules/co/index.js:99:29)
    at onFulfilled (/Users/wangql/src/egg-restapi-module-tool/node_modules/co/index.js:69:7)
    at /Users/wangql/src/egg-restapi-module-tool/node_modules/co/index.js:54:5
    at new Promise (<anonymous>)
    at Object.co (/Users/wangql/src/egg-restapi-module-tool/node_modules/co/index.js:50:10)
    at converted (/Users/wangql/src/egg-restapi-module-tool/node_modules/koa-convert/index.js:17:15)
    at dispatch (/Users/wangql/src/egg-restapi-module-tool/node_modules/koa-compose/index.js:42:32)
    at fn (/Users/wangql/src/egg-restapi-module-tool/node_modules/egg-core/lib/loader/mixin/middleware.js:107:29)
    at dispatch (/Users/wangql/src/egg-restapi-module-tool/node_modules/koa-compose/index.js:42:32)
    at createGenerator (/Users/wangql/src/egg-restapi-module-tool/node_modules/koa-convert/index.js:24:16)
    at createGenerator.next (<anonymous>)
    at onFulfilled (/Users/wangql/src/egg-restapi-module-tool/node_modules/co/index.js:65:19)
    at /Users/wangql/src/egg-restapi-module-tool/node_modules/co/index.js:54:5
statusCode: 401
status: 401
code: 401
message: "Unauthorized request: no authentication given"
name: "unauthorized_request"
pid: 42221
hostname: blessdeiMac.local

前端界面登录报错401

image

image

image

问题描述:

使用npm run dev启动,前端登录界面无法登录进去,一直报401错误。

后端界面能正常登录进去,后台接口访问正常,比如http://127.0.0.1:7001/api/restql/web_admin
我本地分别使用的 http://127.0.0.1:7001/http://127.0.0.1:8080/ 进行访问,白名单里都有。
npm插件都安装正常。

本地配置:

mysql 5.6.35
node 9.2.0
npm 5.5.1

疑问:

  1. 这个401认证的问题如何解决?
  2. static里service的app.js里请求的/api/restql/users/${uid}这个接口路径,但是现在最新的代码接口实际是/api/restql/web_admin,不是users了。

谢谢!

npm exit when I try to add background image in the less file.

I failed to add background image in the less. Could you please help me?

.welcome { height: 328px; background: url(../img/yay.jpg) no-repeat center 0; background-size: 388px 328px; }

10% building modules 0/1 modules 1 active ...rous\static\src\routes\IndexPage.lessP:\workspace\node_modules\loader-runner\lib\loadLoader.js:35
throw new Error("Module '" + loader.path + "' is not a loader (must have normal or pitch function)");
^

Error: Module 'P:\workspace\node_modules\url\url.js' is not a loader (must have normal or pitch function)
at loadLoader (P:\workspace\node_modules\loader-runner\lib\loadLoader.js:35:10)
at iteratePitchingLoaders (P:\workspace\node_modules\loader-runner\lib\LoaderRunner.js:169:2)
at runLoaders (P:\workspace\node_modules\loader-runner\lib\LoaderRunner.js:362:2)
at NormalModule.doBuild (P:\workspace\node_modules\webpack\lib\NormalModule.js:179:3)
at NormalModule.build (P:\workspace\node_modules\webpack\lib\NormalModule.js:268:15)
at Compilation.buildModule (P:\workspace\node_modules\webpack\lib\Compilation.js:146:10)
at factoryCallback (P:\workspace\node_modules\webpack\lib\Compilation.js:329:11)
at factory (P:\workspace\node_modules\webpack\lib\NormalModuleFactory.js:253:5)
at applyPluginsAsyncWaterfall (P:\workspace\node_modules\webpack\lib\NormalModuleFactory.js:99:14)
at P:\workspace\node_modules\tapable\lib\Tapable.js:250:11

npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "client"
npm ERR! node v6.8.1
npm ERR! npm v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! [email protected] client: webpack-dev-server --port 8008 --inline --hot --watch --progress --config ./static/build/webpack.dev.config.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] client script 'webpack-dev-server --port 8008 --inline --hot --watch --progress --config ./static/build/webpack.dev.config.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the vigorous package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! webpack-dev-server --port 8008 --inline --hot --watch --progress --config ./static/build/webpack.dev.config.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs vigorous
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls vigorous
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! P:\workspace\npm-debug.log

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.