项目作者: imhazige

项目描述 :
A template project will use expressjs as backend and ReactJS-AdminLTE as frontend.
高级语言: JavaScript
项目地址: git://github.com/imhazige/expressjs-adminlte-project-template.git
创建时间: 2018-04-11T02:12:11Z
项目社区:https://github.com/imhazige/expressjs-adminlte-project-template

开源协议:MIT License

下载


A full-stack boilerplate template project using expressjs as backend
and AdminLTE as theme. react as front-end

This project is based on react-starter-kit

Usage:

clone from github

  1. git clone https://github.com/imhazige/expressjs-adminlte-project-template.git

install yarn if need npm install --global yarn

cd to the folder

run yarn install

develop run yarn start

release run yarn start -- --release

build run yarn run build -- --release, then node build/server.js

deploy to heroku

  • run yarn run build release and add the build folder to git
  • make sure yarn.lock did not added to the git
  • push to heroku

note:

  • the config PORT only work for built running like node build/server.js

More usage refer to react-starter-kit start guid and doc list

AdminLayout

see the example page: [lte-test] (./src/routes/lte-test/index.js)

Define client side navigate page

see src/routes/index.js

in folder src/routes define page with the page name as a subfolder, need a index.js as a main script and include the component under the same folder or in the component folder do the rendering.

Define React Component

in folder src/components, define a component with a named folder, must include a package.json

Static assets

in folder public

Server side config

in the code src/config.js

Database

connect with sequelize src/data/sequelize.js
sequelize model defined under src/data/models

normally you need not remove the User… Models, as the passort code depend on it.

Sync all defined models to the DB

see

Server API middleware

see

Logging

using log4js
see <./src/common/log.js>, config is in the <./src/config.js>

resource load

you can import image directly like

  1. import userimg from './logo-small.png';
  2. <img src={userimg} className="img-circle" alt="User Image" />;

or put the image under the public folder which will be accessabile via path “/“

you can load css directly via css loader

  1. import s from './Navigation.css';
  2. <div className={s.someclass}>
  3. export default withStyles(s)(Navigation);

class imported from modules is able to refer to class name directly.

ajax request

  1. import fetch from 'node-fetch';
  2. fetch(url)
  3. .then(res => res.json())
  4. .then(json => {
  5. })
  6. .catch(err => {});

Unit Test

run yarn run test will run all the test script with file extension .test.js
run yarn run test <path-to-xxx.test.js> will run the one test script

$ API Test

see <./test/api/t1.test.js> as a example

  • create a test with extension .test.js
  • use apitest function from <./test/api/apitest.js>

Single script test using babel-node

Add script in package.json
"rone": "babel-node"
Then at the root folder of the project, run yarn rone <path-to-script>

Problems need take care

error “Please install sqlite3 package manually”

run

  1. yarn add sqlite3

import css in css will have problem if there are relative resource.

If you import external CSS file from your internal CSS then it will be inlined and processed with CSS modules.
instead, you should import css from js

comment style in css file will cause show css imported from js as content

for example / /

can not use adminlte react directly

it try to resolve the react from its own dependency - ‘ERROR in ./node_modules/adminlte-reactjs/node_modules/react-dom/lib/ReactDOMInvalidARIAHook.js’

html component used in server.js to handle many pages like error

so be careful when you think you need change the html component. or if you should consider deffiernt html for different page
if you want load different resource.

decoratorsLegacy problem

look into this pull, https://github.com/kriasoft/react-starter-kit/pull/1608/files, add these two lines to coresponding code if you encountered these problem.

client javascript library import made error in the phase of server side render

  • error like document is not defined
    use import on the top of the code will cause import in server side render phase, to solve it, use client side require in the client code
    example:

    1. componentDidMount = () => {
    2. //import echarts when component loaded
    3. const echarts = require('echarts');
    4. ...
    5. }

can not use variable for require function

it require to use defined string when invoke require, also __dirname will be the build folder instead, do not rely on it.

  1. const s = '../model'
  2. var model = require(s).default; //error
  3. var model = require('../model').default //correct

Invalid Option: ‘true’ is not a valid value for ‘targets.forceAllTransforms’

refer to the issue