server: rm express dependency, that's 200kb less
This commit is contained in:
parent
a2b387da4d
commit
1be1c729ed
2 changed files with 28 additions and 23 deletions
|
|
@ -36,7 +36,6 @@
|
|||
"electron-packager-plugin-non-proprietary-codecs-ffmpeg": "1.0.2",
|
||||
"eslint": "5.11.1",
|
||||
"exorcist": "1.0.1",
|
||||
"express": "4.16.4",
|
||||
"file-saver": "2.0.0",
|
||||
"gyronorm": "2.0.6",
|
||||
"jquery": "3.3.1",
|
||||
|
|
@ -56,6 +55,7 @@
|
|||
"python-shell": "1.0.7",
|
||||
"scope-css": "1.2.1",
|
||||
"screenfull": "4.0.0",
|
||||
"send": "^0.16.2",
|
||||
"source-map-support": "0.5.9",
|
||||
"stacktrace-js": "2.0.0",
|
||||
"through": "2.3.8",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
var express = require('express')(),
|
||||
path = require('path'),
|
||||
var path = require('path'),
|
||||
send = require('send'),
|
||||
http = require('http'),
|
||||
server = http.createServer(express),
|
||||
server = http.createServer(httpRoute),
|
||||
Ipc = require('./ipc/server'),
|
||||
ipc = new Ipc(server),
|
||||
settings = require('./settings'),
|
||||
|
|
@ -11,26 +11,31 @@ var express = require('express')(),
|
|||
osc = {},
|
||||
clients = {}
|
||||
|
||||
express.get('/', function(req, res){
|
||||
res.sendFile(path.resolve(__dirname + '/../client/index.html'))
|
||||
})
|
||||
|
||||
express.get('*', function(req, res){
|
||||
if (req.path.indexOf('theme.css') != -1) {
|
||||
res.set('Content-Type', 'text/css')
|
||||
if (settings.read('theme')) {
|
||||
var str = theme.get(),
|
||||
buf = Buffer.from && Buffer.from !== Uint8Array.from ? Buffer.from(str) : new Buffer(str)
|
||||
res.send(buf)
|
||||
} else {
|
||||
res.send('')
|
||||
}
|
||||
} else if (/(assets|client)\//.test(req.path)){
|
||||
res.sendFile(path.resolve(__dirname + '/..' + req.path))
|
||||
} else {
|
||||
res.sendFile(path.resolve(req.path))
|
||||
function httpRoute(req, res) {
|
||||
res.sendFile = (path)=>{
|
||||
send(req, path).pipe(res)
|
||||
}
|
||||
})
|
||||
|
||||
if (req.url === '/' || req.url.indexOf('/?') === 0) {
|
||||
res.sendFile(path.resolve(__dirname + '/../client/index.html'))
|
||||
} else {
|
||||
if (req.url.indexOf('theme.css') != -1) {
|
||||
res.setHeader('Content-Type', 'text/css')
|
||||
if (settings.read('theme')) {
|
||||
var str = theme.get(),
|
||||
buf = Buffer.from && Buffer.from !== Uint8Array.from ? Buffer.from(str) : new Buffer(str)
|
||||
res.write(buf)
|
||||
} else {
|
||||
res.write('')
|
||||
}
|
||||
res.end()
|
||||
} else if (/^\/(assets|client)\//.test(req.url)){
|
||||
res.sendFile(path.resolve(__dirname + '/..' + req.url))
|
||||
} else {
|
||||
res.sendFile(path.resolve(req.url))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
server.listen(settings.read('httpPort'))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue