This repository was archived by the owner on Jan 20, 2023. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
119 lines (110 loc) · 3.64 KB
/
Copy pathindex.js
File metadata and controls
119 lines (110 loc) · 3.64 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
'use strict';
const express = require('express');
const router = express.Router();
const options = require('../grove-node-server-utils/options')();
const authProvider = require('../grove-node-server-utils/auth-helper');
const four0four = require('../grove-node-server-utils/404')();
const enableLegacyProxy = true; // TODO: expose this as an env option
if (options.maintenanceMode) {
router.all('*', four0four.maintenanceMode);
}
router.use('/api', require('./api'));
// This is a legacy proxy to the MarkLogic REST API.
// Best practice is to create endpoints in this middle-tier and to
// avoid directly calling MarkLogic APIs from the UI.
// But sometimes, particularly for demos and PoCs, it is helpful
// to punch through the middle-tier.
//
// A minimum of proxies are setup by default, and we will eventually
// replace those with Grove middle-tier endpoints.
//
// Further down in this file, you will find more examples
// of other proxies that can be setup.
if (enableLegacyProxy) {
router.use(
/\/v1|\/LATEST/,
require('../grove-legacy-routes').whitelistProxyRoute({
authProvider: authProvider,
whitelist: [
{
endpoint: '/suggest',
methods: ['get', 'post'],
authed: true // return 401 if user not authenticated to middle-tier
// when `authed: false`, will authenticate proxied request if the
// user is authenticated. If not authenticated, it will still allow
// a request without authentication.
},
// Follow this pattern for other REST extensions
{
endpoint: '/resources/extsimilar',
methods: ['get'],
authed: true
},
// TODO: move this to visjs documentation for visjs-graph
// Other possibilities:
// {
// endpoint: '/config/query/*',
// methods: ['get'],
// authed: true
// },
{
endpoint: '/graphs/sparql',
methods: ['post'],
authed: true
}
// {
// endpoint: '/search',
// methods: ['get', 'post'],
// authed: true
// },
// {
// endpoint: '/values/*',
// methods: ['get', 'post'],
// authed: true
// },
// {
// endpoint: '/documents',
// methods: ['get'],
// authed: true
// },
// {
// endpoint: '/documents',
// methods: ['all'],
// authed: true,
// update: true
// },
// {
// endpoint: '/resources/*', // NOTE: allows get on all extensions
// methods: ['get'],
// authed: true
// },
// {
// endpoint: '/resources/*', // NOTE: this is for put, post, delete
// // which fall through after the 'get' above
// // CAUTION: exposes all REST extensions, even future ones
// methods: ['all'],
// authed: true,
// update: true
// }
]
})
);
}
// This sets up this middle-tier to serve static assets found in the
// directory specified by GROVE_UI_BUILD_PATH (if that is set).
//
// If you will never use this middle-tier to serve such assets (for
// example, if you are following the best practice of using a reverse proxy
// like Nginx or HAProxy to serve them instead), you can remove these lines.
if (options.staticUIDirectory) {
router.use(
require('../grove-default-routes').defaultStaticRoute({
staticUIDirectory: options.staticUIDirectory
})
);
}
// error handling
router.use(function(error, req, res, next) {
res.status(500).json({ message: error.toString() });
});
module.exports = router;