Skip to content

Commit

Permalink
Tomomaster: enable https on local with "npm run dev-https"
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhnguyennguyen committed Dec 3, 2018
1 parent 2c47295 commit b35a42d
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 13 deletions.
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@ This is Governance Dapp for TomoChain. Full-Node can apply to become a candidate
```
cp config/default.json config/local.json
```
Update `local.json` file to support your environment
- Update mnemonic
- Update mongodb configuration:
- For docker:
` "db": {
"uri": "mongodb://mongodb:27017/governance"
- Update `local.json` file to support your environment
- Update mnemonic
- Update mongodb configuration:
- For docker:
` "db": {
"uri": "mongodb://mongodb:27017/governance"
},
`
- For localhost:
`
"db": {
"uri": "mongodb://localhost:27017/governance"
},
`
- For localhost:
`
"db": {
"uri": "mongodb://localhost:27017/governance"
},
`


## Install
```
Expand All @@ -40,6 +39,8 @@ cp abis/*json build/contracts/
```
Note: before deploying to tomochain testnet, make sure you have TOMO in the wallet. If not, get free at [https://faucet.tomochain.com](https://faucet.testnet.tomochain.com)

## Enable https
``` npm run dev-https```
## Run
- Start mongodb
- Start TomoMaster
Expand Down
43 changes: 43 additions & 0 deletions index_https.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict'

const express = require('express')
const config = require('config')
const bodyParser = require('body-parser')
const validator = require('express-validator')
const path = require('path')
const fs = require('fs')
const https = require('https')
const privateKey = fs.readFileSync(path.resolve(__dirname, 'sslcert/server.key'))
const certificate = fs.readFileSync(path.resolve(__dirname, 'sslcert/server.crt'))

const credentials = { key: privateKey, cert: certificate }
// body parse
const app = express()

const server = https.Server(credentials, app)

app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.use(validator({}))

app.use('/build', express.static('build'))
app.use('/app/assets', express.static('app/assets'))

// apis
app.use(require('./apis'))

// error handler
app.use(require('./middlewares/error'))

app.get('*', function (req, res) {
return res.sendFile(path.join(__dirname, 'index.html'))
})

// start server
server.listen(config.get('server.port'), config.get('server.host'), function () {
const host = server.address().address
const port = server.address().port
console.info('Server start at https://%s:%s', host, port)
})

module.exports = app
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"webpack": "node ./node_modules/webpack/bin/webpack.js -d --w",
"test": "./node_modules/.bin/truffle test",
"dev": "npm run crawl-dev & npm run nodemon & cross-env NODE_ENV=development webpack-dev-server --hot --host 0.0.0.0 --port 3000",
"dev-https": "npm run crawl-dev & ./node_modules/.bin/nodemon index_https.js & cross-env NODE_ENV=development webpack-dev-server --config webpack.https.config.js --https --key ./sslcert/server.key --cert ./sslcert/server.crt --hot --host 0.0.0.0 --port 3000",
"build": "cross-env NODE_ENV=production webpack -p --progress --hide-modules",
"abis": "node ./abis.js",
"coverage": "./node_modules/.bin/solidity-coverage",
Expand Down Expand Up @@ -47,6 +48,7 @@
"express-validator": "^5.1.2",
"highcharts": "^6.1.1",
"highcharts-vue": "^1.0.4",
"https": "^1.0.0",
"kue": "^0.11.6",
"lodash": "^4.17.10",
"moment": "^2.22.2",
Expand Down
23 changes: 23 additions & 0 deletions sslcert/server.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-----BEGIN CERTIFICATE-----
MIID3jCCAsagAwIBAgIJAICwNRUjukmSMA0GCSqGSIb3DQEBCwUAMIGDMQswCQYD
VQQGEwJWTjEOMAwGA1UECAwFSGFub2kxDjAMBgNVBAcMBUhhbm9pMRIwEAYDVQQK
DAlUb21vY2hhaW4xFTATBgNVBAMMDE5ndXllbk5ndXllbjEpMCcGCSqGSIb3DQEJ
ARYabmd1eWVubmd1eWVuQHRvbW9jaGFpbi5jb20wHhcNMTgxMTIwMDcwODMwWhcN
MTkxMTIwMDcwODMwWjCBgzELMAkGA1UEBhMCVk4xDjAMBgNVBAgMBUh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 additions & 0 deletions sslcert/server.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCdmHmboIraHvca
gSLb0ShrNPBvcMsU25fkYrawa+q9kMI6js8Dyq/WrI4c9a7o++1u+iYDviXR3E4n
JhAYS3d7IpWBFlqkWr78/HyvBdQrfMuAI/RETu1KZLuYEhr+LcMPjDaJi8/GbP7V
flAZfmcpXQbb4nYoK+lE2bXHRBERRvGv069VyDhBSEwmSr2rolws1SpxajdenlKU
s8TTsN3YObyq0bMRWKmh8W35BwVYnS9qZRRei4gdBK6njNHLtq3mUxn1Mr4OGtjM
9raaXvRTReqMe9rqB9zushBxl/SV5eQcy42HUa7v9ggyoLoQNJqLRxaI7ytK/Viz
Ykq1awnZAgMBAAECggEAY7hAcs5SLhTb7QR7hzZA6h1Ual+n0SnmYdhomxeeMJcx
n5YPvel5/E+xmPeI1tnacpeMiF/AVJufRDxcgNL35o2KpmT7s/XL1g754lHA4EeW
CR43CSYcFi/JWD9UnzNbszHYrI4wSfFcCsFjc848/rpjha01cNPgRfWwhUc3uYL5
YoTrWuDrCJxQqUYChMRsO3IeymBvtvml20YUR9hvzNE5IW3A/k9UYGNBJt5MGVKH
OIycg5nq0294eZXE6E9NHOZs5OP/1xdsaJUuFws2VfdI7S5llAOyQWz9lLtaSf5o
WvSs6lLda635PMLx/f8BM61mU28U/JVIxkvDJp1GZQKBgQDLa3rLkGRbUQlWQCvc
Dkbtv8VFWGWNpHHG1WUMJE8lgAJVaX+lnOA3eOd618NwujSzSI6gI+QtuYd69vg3
c0RiWiDoLsEeW2EFUPcnkKjADWuoAv5MAdpVCsuRBTVsZ3pjUShrCKMXkWXW/TcK
y/fjEMs4rjsA7bjr8xs8ZQMENwKBgQDGVMECV6iCsbCb62zuc0fIIxRJ8QOQR0ZK
Hpxwjo9i1jtHze4fewZHdIvuXQfto9F4eiQ0x11s40Y1+TnoevQvQqmpQEF64uNj
RC6VKqgdSeLV1CxB7gD1QWMZbIPTCVUsE8QG3PyJahYaiSooKIs4npAgmECDNlr6
01/YVrZ6bwKBgFheKov///jDbWDwo50G/r0Nj+8eBY/QnjSYQztREqjhwSHFoNQb
IDQ466Yr0RVJbtdrb7oVnWxXqok6fH3qLwzixmTW2sILREyA7b1cVFKKAfiMxFfU
fjpvZBttvdWH5lz6xqooqGD2ot0QRzcDgH49r2rCFZPDsY+ennhQEU1lAoGBAI7s
bNq/SNRGMLtsAOglc0kq3mgaozLJ6kFnpd0HHxVexQGNyVguU+wSdPSlXh1GvKFR
g930/cKGVgZ3P9/lGysjoxgxEf74mlziuZ8NSnEw2aK2b95jIZWcNUoRBT6DrzlA
VTeM8QAlzx/4UMT30rxOqBaVIYhtF0tCIAPLGV1JAoGASrGKf28LLRZTps4fckRu
JqUvzfN58lldUWRkyJQlz9N9oU+Asru8SgfPslRPb5mVDtGzbnMqCVkxUVEZ4cOL
wwxh62VDrTJ1OZGuHsapeEY77mNGkMjqYRBw/zbBSFOtEXEtezEH8Ki3JWRE3KN7
Na0Po2W9YQr2IuGCLYv9DLM=
-----END PRIVATE KEY-----
131 changes: 131 additions & 0 deletions webpack.https.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
var path = require('path')
var webpack = require('webpack')
var appName = '[name].js'
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')

module.exports = {
mode: 'development',
entry: {
app: './app/app.js',
style: './app/assets/scss/style.scss'
},
output: {
path: path.resolve(__dirname, './build'),
publicPath: '/build/',
filename: appName
// chunkFilename: 'chunks/[chunkhash].js',
// jsonpFunction: 'pluginWebpack'
},
optimization: {
minimize: process.env.NODE_ENV === 'production',
splitChunks: {
name: 'app'
}
},
module: {
rules: [
{
enforce: 'pre',
test: [/\.js$/, /\.vue$/],
exclude: [/node_modules/],
loader: 'eslint-loader'
},
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
]
},
{
test: /\.scss$/,
exclude: [/node_modules/],
use: [
'vue-style-loader',
'css-loader',
'sass-loader'
]
},
{
test: /\.vue$/,
loader: 'vue-loader',
exclude: /node_modules/,
options: {
loaders: {
'scss': [
'vue-style-loader',
'css-loader',
'sass-loader'
]
}
// other vue-loader options go here
}
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]'
},
exclude: /node_modules/
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader',
exclude: /node_modules/
}
]
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js',
'app': path.resolve('./app/app.js'),
'style': path.resolve('./app/assets/scss/style.scss')
},
extensions: ['*', '.js', '.vue', '.json']
},
devServer: {
historyApiFallback: true,
noInfo: true,
overlay: true,
proxy: {
'/api': {
target: 'https://localhost:3001',
secure: false,
changeOrigin: true
}
}
},
performance: {
hints: false
},
devtool: '#eval-source-map'
}

if (process.env.NODE_ENV === 'production') {
module.exports.devtool = '#source-map'
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.LoaderOptionsPlugin({
minimize: true,
minimizer: new UglifyJsPlugin({
uglifyOptions: {
sourceMap: true,
compress: {
warnings: false
}
}
})
})
])
}

0 comments on commit b35a42d

Please sign in to comment.