This repository was archived by the owner on May 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.js
More file actions
59 lines (56 loc) · 2.04 KB
/
install.js
File metadata and controls
59 lines (56 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var http = require('http')
var fs = require('fs')
var path = require('path')
var parseForm = function (data) {
var parts = 'set ' + decodeURIComponent(data.replace(/&/g, '\r\nset '))
return parts
}
var checkFile = function (res) {
res.writeHead(200, { "content-type": "text/html" })
fs.exists(path.join(__dirname, 'server.p12'), function (exists) {
if (exists) {
res.end(fs.readFileSync(path.join(__dirname, 'installsuccess.html')))
console.log('it is supposed to crash now')
response.end()
} else {
res.writeHead(500, { "content-type": "text/html" })
var page = fs.readFileSync(path.join(__dirname, 'installcertmissing.html'), { encoding: 'utf8' }).replace('{{folder}}', __dirname)
console.log(typeof page)
res.end(page)
}
})
}
var server = http.createServer(function (req, res) {
if (req.method == 'GET') {
res.writeHead(200, { "content-type": "text/html" })
res.end(fs.readFileSync(path.join(__dirname, 'install.html')))
} else if (req.method == 'POST') {
console.log(req.url)
var body = ''
req.on('data', function (data) {
body += data
})
req.on('end', function (data) {
if (data) {
body += data
}
if (req.url == '/') {
var startbat = parseForm(body)
startbat += '\r\nnodemon app.js'
fs.writeFile(path.join(__dirname, 'start.bat'), startbat, function (err) {
if (err) {
console.log(err)
res.writeHead(500, { "content-type": "text/plain" })
res.end('an error occured, try again please')
} else {
checkFile(res)
}
})
} else if (req.url == '/ready') {
checkFile(res)
}
})
}
})
console.log('start server on ' + process.env.PORT)
server.listen(process.env.PORT)