-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.ls
73 lines (61 loc) · 1.91 KB
/
app.ls
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require! {
\express
\nocache
\body-parser
\serve-static
\blockstarter-wl
\hashcash-token
\ddos
\./package.json : pack
\prelude-ls : { map }
\./contract-api.js
}
{ getFrontendData } = contract-api
{ config } = pack
app = express!
app.use nocache!
__path = __dirname + \/public
if config.performance.keep-static-in-memory
app.use(serve-static(__path, { max-age: \0 }))
else
app.use express.static( __path )
if config.performance.use-ddos-protection
protection = new ddos config.request-limits
app.use protection.express
console.log "init route /"
app.get \/ , (req, res)->
res.redirect \/login/index.html
app.use body-parser.json!
transform = (key, data, cb)->
#console.log data
switch key
case \panel
getFrontendData data, cb
else
cb null, data
create-route = (key)->
console.log "init route /api/#{key}"
req, resp <-! app.post "/api/#{key}"
ip = req.headers[\x-forwarded-for] ? req.connection.remote-address.replace('::ffff:', '')
if config.performance.require-request-payment
requestpayment = req.headers.requestpayment
return resp.status(403).end! if not requestpayment?
[nonce_str, hash, rarity_str] = requestpayment.split('|')
nonce = parse-int nonce_str
rarity = parse-float rarity_str
difficulty = 1000
data = "#ip/#key"
#valid =
# hashcash-token.validate({ nonce, hash, rarity, data , difficulty } )
#return resp.status(401).end! if not valid
request = {} <<<< req.body <<<< config
request.ip = ip
delete request.dashboard
delete request.performance
err, data <-! blockstarter-wl[key] request
return resp.status(400).send(err.response?text) if err?
err, transformed <-! transform key, data
return resp.status(500).send(err) if err?
resp.send transformed
blockstarter-wl |> Object.keys |> map create-route
module.exports = app