-
Notifications
You must be signed in to change notification settings - Fork 1
/
pgserver.js
74 lines (62 loc) · 2.28 KB
/
pgserver.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
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
74
const pgserverconfig = require('./config/pgserver.json')
const express = require('express');
const logger = require('morgan');
const cors = require('cors');
const app = express();
app.use(logger('dev'));
app.use(cors());
app.use('/', express.static(__dirname + '/public'));
let adminApp;
if (pgserverconfig.userport === pgserverconfig.adminport) {
adminApp = app;
} else {
if (pgserverconfig.adminport > 0) {
adminApp = express();
adminApp.use(logger('dev'));
adminApp.use(cors());
}
}
if (adminApp) {
adminApp.use('/admin', express.static(__dirname + '/admin'));
}
const dbconfig = require('./config/dbconfig.json');
const pgp = require('pg-promise')({
/*query: (e) => {
console.log(e.query);
}*/
});
const readOnlyPool = pgp(dbconfig);
let adminPool;
if (adminApp) {
if (dbconfig.adminuser && dbconfig.user !== dbconfig.adminuser) {
dbconfig.user = dbconfig.adminuser;
dbconfig.password = dbconfig.adminpassword;
adminPool = pgp(dbconfig);
} else {
adminPool = readOnlyPool;
}
}
const DirCache = require('./utils/dircache.js')
const cache = new DirCache(`./cache/${dbconfig.database?dbconfig.database:process.env.PGDATABASE?process.env.PGDATABASE:''}`);
const swagger = require('./swagger.js')(app);
const login = require('./login.js')(app);
const upload = require('./upload.js')(adminApp, adminPool);
const mvt = require('./mvt.js')(app, readOnlyPool, cache);
const geojson = require('./geojson.js')(app, readOnlyPool);
const geobuf = require('./geobuf.js')(app, readOnlyPool);
const listLayers = require('./list_layers.js')(app, readOnlyPool);
const layerColumns = require('./layer_columns.js')(app, readOnlyPool);
const bbox = require('./bbox.js')(app, readOnlyPool, cache);
const query = require('./query.js')(app, readOnlyPool);
const columnStats = require('./column_stats.js')(app, readOnlyPool, cache);
const server = app.listen(pgserverconfig.userport);
server.setTimeout(600000);
console.log(`pgserver listening on port ${pgserverconfig.userport}`);
if (adminApp && adminApp !== app) {
const adminServer = adminApp.listen(pgserverconfig.adminport);
adminServer.setTimeout(600000);
}
if (adminApp) {
console.log(`pgserver admin listening on port ${pgserverconfig.adminport}`)
}
module.exports = app;