Skip to content

Commit

Permalink
added: initialize project
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobs committed Dec 4, 2019
0 parents commit ceb15c6
Show file tree
Hide file tree
Showing 87 changed files with 17,641 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"@babel/plugin-proposal-function-bind",
"@babel/plugin-proposal-class-properties"
]
}
4 changes: 4 additions & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
>1%
not dead
not ie <= 11
not op_mini all
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[*.{js,jsx,ts,tsx}]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/*
package-lock.json
.idea/
dist/static/
110 changes: 110 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# NgRouter Gateway management Portal (NgRouter网关管理控制台)

## 项目安装依赖
```
npm install
```

### 本地环境运行
```
npm run start
```

### 编译打包生产,
```
npm run build
```

### 在config/index.js中,根据不同环境,提供不同的NgrAdmin RESTFUL API域名和端口

```
var path = require('path')
const NODE_ENV = process.env.NODE_ENV
module.exports = {
build: {
restfulApi:'http://product.gateway-api.com',
mode: NODE_ENV,
sourceMap: false,
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: '/',
bundleAnalyzerReport: process.env.analyz
},
dev: {
restfulApi:'http://dev.gateway-api.com',
mode: NODE_ENV,
sourceMap: 'source-map',
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: '/',
port: 3000,
autoOpenBrowser: true,
overlay: true,
historyApiFallback: true,
noInfo: true
},
}
```

### 提供在服务器上pm2启动项目的功能

```
1. 修改config/index, 配置Ngr Admin RESTFUL API server地址。配置一次即可。
var path = require('path')
const NODE_ENV = process.env.NODE_ENV
module.exports = {
build: {
restfulApi:'http://product.gateway-api.com',
mode: NODE_ENV,
sourceMap: false,
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: '/',
bundleAnalyzerReport: process.env.analyz
},
dev: {
restfulApi:'http://dev.gateway-api.com',
mode: NODE_ENV,
sourceMap: 'source-map',
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: '/',
port: 3000,
autoOpenBrowser: true,
overlay: true,
historyApiFallback: true,
noInfo: true
},
}
2. 本地打包编译。
npm run build
3. 推送代码到远程仓库
git push origin xxx
4. 服务器用pm2起node服务
npm run pm2_start
5. 服务器ip+端口访问,如有需要自行配置ngnix做域名解析
```

### 部署建议

- NgrAdmin服务与NgrAdminPortal部署在同一应用实例上,NgrAdminPortal访问本地NgrAdmin服务。











21 changes: 21 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var express = require('express');
var path = require('path');

var app = express();

// 设置模板引擎
app.set('views', path.join(__dirname, 'dist'));
app.engine('.html', require('ejs').__express);
app.set('view engine', 'html');

app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'dist')));

// 接收请求,返回根页面,前端处理页面路由(单页应用)
app.use('/', function(req, res, next) {
res.render('index');
});


module.exports = app;
90 changes: 90 additions & 0 deletions bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

var app = require('../app');
var debug = require('debug')('ngr_webadmin:server');
var http = require('http');

/**
* Get port from environment and store in Express.
*/

var port = normalizePort('3000');
app.set('port', port);

/**
* Create HTTP server.
*/

var server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
84 changes: 84 additions & 0 deletions build/webpack.base.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const config = require('../config')
const NODE_ENV = process.env.NODE_ENV
// style files regexes
const preRegex = /\.(less)$/

function resolve(dir) {
return path.join(__dirname, '..', dir)
}

// common function to get style loaders
const getStyleLoaders = () => {
const preProcessor = 'less-loader'
const loaders = [
NODE_ENV === 'development' ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: true,
localIdentName: '[name]_[local]-[hash:base64:8]',
}
},
{
loader: 'postcss-loader'
},
preProcessor
]

return loaders
}

module.exports = {
entry: resolve('src/index.js'),
resolve: {
extensions: ['.js', '.jsx', '.json']
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
use: [NODE_ENV === 'development' ? 'style-loader' : MiniCssExtractPlugin.loader, 'css-loader'],
},{
test: /\.less$/,
use: ['style-loader', 'css-loader', 'less-loader']
},
// {
// test: preRegex,
// use: getStyleLoaders(),
// exclude: /node_modules/
// },
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: `${config.build.assetsSubDirectory}/img/[name].[hash:8].[ext]`
}
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: `${config.build.assetsSubDirectory}/media/[name].[hash:8].[ext]`
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: `${config.build.assetsSubDirectory}/fonts/[name].[hash:8].[ext]`
}
}
]
}
}
39 changes: 39 additions & 0 deletions build/webpack.dev.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@


const path = require('path')
const webpack = require('webpack')
const merge = require('webpack-merge')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const WebpackServerQRcode = require('@ice-point/webpack-server-qrcode')
const baseWebpackConfig = require('./webpack.base.conf.js')
const config = require('../config')

module.exports = merge(baseWebpackConfig, {
mode: config.dev.mode,
devtool: config.dev.sourceMap,
output: {
path: config.dev.assetsRoot,
filename: path.join(config.dev.assetsSubDirectory, 'js/[name].js'),
chunkFilename: path.join(config.dev.assetsSubDirectory, 'js/[name].chunk.js'),
publicPath: config.dev.assetsPublicPath
},
devServer: {
contentBase: config.dev.assetsRoot,
disableHostCheck:true,
host: config.dev.host,
port: config.dev.port,
open: config.dev.autoOpenBrowser,
inline: true,
hot: true,
overlay: config.dev.overlay,
historyApiFallback: config.dev.historyApiFallback,
noInfo: config.dev.noInfo
},
plugins: [
new WebpackServerQRcode(),
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
template: './src/index.tpl.html'
}),
]
})
Loading

0 comments on commit ceb15c6

Please sign in to comment.