Skip to content

Commit

Permalink
change static server module
Browse files Browse the repository at this point in the history
  • Loading branch information
biuuu committed Mar 23, 2018
1 parent 0ef45ed commit 3f426f4
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 280 deletions.
1 change: 1 addition & 0 deletions electron-builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"files": ["!electron-builder.json", "!electron-builder.local.json", "!userData${/*}", "!.vscode${/*}"],
"asar": true,
"asarUnpack": ["node_modules/serve${/*}", "node_modules/clipboardy${/*}", "node_modules/term-size${/*}"],
"publish": [{
"provider": "github",
"repo": "BLHXFY",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"lodash": "^4.17.5",
"papaparse": "^4.3.7",
"rimraf": "^2.6.2",
"serve": "^6.5.3",
"st": "^1.2.2",
"urijs": "^1.19.0",
"url-search-params": "^0.10.0",
"vue": "^2.5.13"
Expand Down
9 changes: 3 additions & 6 deletions store/staticMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const glob = require('glob')
const path = require('path')
const chokidar = require('chokidar')
const { STATIC_PATH } = require('../store')
const serve = require('serve')
const startServer = require('../utils/staticServer')
const CONFIG = require('../config')
const fse = require('fs-extra')
const { app } = require('electron')
Expand Down Expand Up @@ -36,11 +36,6 @@ const collectFiles = (type, once) => {

collectFiles('local')

const server = serve(STATIC_PATH, {
port: CONFIG.staticPort,
cors: true
})

const watchFile = (type) => {
chokidar.watch(`${type}/**/?*`, {
cwd: STATIC_PATH,
Expand Down Expand Up @@ -72,4 +67,6 @@ setTimeout(() => {
watchFile('default')
}, 3000)

startServer(STATIC_PATH, CONFIG.staticPort)

module.exports = staticMap
13 changes: 13 additions & 0 deletions utils/staticServer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var st = require('st')
var http = require('http')

const startServer = (stPath, port) => {
http.createServer(
st({
path: stPath,
cors: true
})
).listen(port)
}

module.exports = startServer
Loading

0 comments on commit 3f426f4

Please sign in to comment.