🧛Comes from 🏰 and 👿, it work as basic dev structure & simple api proxy.
2020/02
- ADD server side rendering support
- ADD log helper
- ADD babel plugin for dynamic import and webpack plugin for manifest, thanks for @loadable
2019/07
- UPDATE example project & some webpack configure
2019/05
- ADD MIT license
- UPDATE bundler version to
webpack 4.x
,babel 7.x
- UPDATE install package process check function to
npm search
- UPDATE server side rendering
- UPDATE default babel loader support
.babelrc
2019/04
- ADD auto install package webpack plugin
- UPDATE webpack bundler from main to child process
- UPDATE auto refresh server config under dev mode
- 新建一个git空项目
- 执行命令
git submodule add [git-http/ssh] lib
- 运行
git submodule init && git submodule update
- 执行
cp -rf ./lib/example/* .
- 生成的lib目录请勿随意更改,如果需要更新库代码请执行以下代码
npm run lib
或git submodule update -f && git submodule foreach git pull origin [branch]
- 更新后的lib引用切记同步到git
- 执行
npm install
- 请进入
src
目录开发 - 启动开发模式
npm start
- 启动上线模式
npm run build
默认输出目录为 ./public/project/, 如需更改请修改dracula.config.js中的output
Deprecated
import { HttpTool } from './lib/utils'
或者
import { utils } from './lib';
let HttpTool = utils.HttpTool
-
typeEnum
Enum object, current is{ POST: 'post', GET: 'get', PUT: 'put', DELETE: 'delete' }
-
request
Function(type, api_type, successCallback, failCallback, param, reqOptions)
,type
is value lists in typeEnum.reqOption
is extra options pass to backend server, current support {isFormData,isRefer,ipKey}isFormData
(boolean) param need to construct to meetapplication/x-www-form-urlencoded
requirmentisRefer
(boolean) api_type arg can contain 'http(s)://' to requestipKey
(string) use value with target key lists in server config of dracula.config.js, value format refers to serviceIP
if you don't want to define request `type` in request, you can use `HttpTool.post` or `HttpTool.get`...with same arguments follow which list in typeEnum object.
-
saveUserInfo
Function(userinfo, save, keyName), setuserinfo
according tokeyName
, if not given use default user key 'DEMON_USER' in helper,save
means cookie expired in how many days. -
getUserInfo
Function(keyName?), get user info according tokeyName
from cookie, if not givenkeyName
in first time, use default user key 'DEMON_USER' in helper or it will use the value when callsaveUserInfo
above. -
cleareUserInfo
Function(), clear user info in cookie, no matter it exists or not. -
getCookieInfo
Function(cookieKey), get cookie value according to cookie key, returnnull
if not exists, or return string or JSON data. -
saveCookieInfo
Function(key, value, time), save cookie value withkey
,value
and expiretime
. -
clearCookie
Function(), clear all cookie.
express config options
DEV
property is set server whether running under DEV mode, true
means dev mode, default: true
manifestPath
means the file path which bundled resources for web, main for filter out which dynamic import chunks will be loaded and told browser which chunks should be waiting before load content.
set debug ip pass configuration
type
property is used to set ip pass type, query
and path
query
means debug ip passed through url parameters, eg.http://localhost:3000/?ip=192.168.1.1:8008
path
means debug ip passed through path, eg.http://localhost:3000/192.168.1.1:8008/
queryKey
property is to set what key value to parse the debug ip, default is ip
, eg. http://localhost:3000/?ip=192.168.1.1:8008
, it will not work with type
above with value 'path'
serviceIP
property is set target server, can be changed when in dev mode and address followed with address[:port]
, default: 10.0.0.182:9092
addrMap
property is the object with key: [...]
to set address mapping for visiting address directly, and key
value MUST start with type of http
or https
eg.
when you visiting the website, its address is http://www.example.com/visit
, and set addrMap
property with object like this: {"http://127.0.0.1":["http://www.example.com", "http://localhost:3000"]}
, then transfer Host will set to its key [in this example is http://127.0.0.1
], but when you visit the site of http://www.example2.com/search
, it still transfer to default setting of serviceIP.
Addresses set need to include PORT and HTTP type, eg. if your object like {"http://127.0.0.1":["http://localhost"]}
, it mean all visits from address of http://localhost
like: http://localhost:3000
, http://localhost:3001
will transfer to http://127.0.0.1
, but https://localhost
or http://127.0.0.1:3000
will not work
browserSupport
property is used for set browser support with default IE version in number type, default: 8
blockPageName
property is set page path showing for browserSupport not passed, best for absolute path, default: hintPage.html
port
property means port to run server, default: 3001
restfulSupport
property restrict which type of request type support by this server, if type not in array, use type index 0 of the array, default: ['post', 'get', 'put', 'delete']
viewPath
property set the view
path of express server
assetPath
property set the static resources
path of express server
acceptHeaders
property is used to transfer the specific headers from client to back end server
contentEncoding
property is used to set accept-encoding
with target value,default is gzip, deflate, br
, if don't need content compress set value to none
to close it
custom
setting for server config include custom routes
- @params: req
- @params: res
- @params: next
- @returns: void
serverRoutes
is the function for custom express routes injection.
webpack config options
which webpack version to use if install different versions in lib folder and outside, true
means use inner webpack, default: true
dev mode webpack options
enable webpack-bundle-analyzer
in dev/release webpack config
assign this to replace partitial/total dev/release webpack config of preset webpack config
release mode webpack options
additional webpack config for server side pack up like resolve or other.
-
Loader and Plugin extraction[2018-01-08] -
Pack up[2018-01-08] -
Auto install missing package under dev mode[2019-04-25] -
Auto reload server setting under dev mode[2019-04-23]