-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
32 lines (26 loc) · 945 Bytes
/
app.js
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
const config = require('./config')
const ln = require('./lightning')
//database - mostly for tokens
const db = require('knex')(config.knex)
//debuging
const debug = require('debug')('app:main')
///express stuff here
const bodyParser = require('body-parser')
const express = require('express')
const app = express()
app.use(bodyParser.json())
//logging & authorization & basic error handling function
app.use((error,req,res,next) => {
debug(req.method+' '+req.url)
if(error) {
return res.status(error.status).json({errorCode:99,errorMessage:error.type+" "+error.message})
}
if(req.headers["x-auth-key"] != '111') {
return res.status(401).json(config.errors['UNAUTHORIZED'])
}
next()
})
app.use(config.rpcMountPoint || '/rpc',require('./rpc'))
app.use(config.apiMountPoint || '/api',require('./api'))
const port = process.env.PORT || 3000
app.listen(port, _ => debug("API started on port "+port))