-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
45 lines (37 loc) · 1.4 KB
/
server.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
var express = require('express');
var cors = require('cors');
var reveal = require('reveal-sdk-node');
const app = express();
app.use(cors()); // DEVELOPMENT only! In production, configure appropriately.
app.use(express.static('public'));
const authenticationProvider = async (userContext, dataSource) => {
if (dataSource instanceof reveal.RVPostgresDataSource) {
return new reveal.RVUsernamePasswordDataSourceCredential("postgres", "postgres");
}
return null;
}
const dataSourceProvider = async (userContext, dataSource) => {
if (dataSource instanceof reveal.RVPostgresDataSource && dataSource.id === "PostgreInventryDb") {
dataSource.host = "localhost";
dataSource.database = "postgres";
}
return dataSource;
}
const dataSourceItemProvider = async (userContext, dataSourceItem) => {
if (dataSourceItem instanceof reveal.RVPostgresDataSourceItem) {
dataSourceProvider(userContext, dataSourceItem.dataSource);
if (dataSourceItem.id === "StockItems") {
dataSourceItem.table = "stock_items";
}
}
return dataSourceItem;
}
const revealOptions = {
authenticationProvider: authenticationProvider,
dataSourceProvider: dataSourceProvider,
dataSourceItemProvider: dataSourceItemProvider,
}
app.use('/', reveal(revealOptions));
app.listen(8080, () => {
console.log(`Reveal server accepting http://localhost:8080/`);
});