@igea/oac_backend 1.0.73 → 1.0.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@igea/oac_backend",
3
- "version": "1.0.73",
3
+ "version": "1.0.74",
4
4
  "description": "Backend service for the OAC project",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -38,6 +38,12 @@ module.exports = function(jwtLib){
38
38
  }
39
39
 
40
40
  router.get('/exposed_config', (req, res) => {
41
+ const ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress;
42
+ if(ip.includes("127.0.0.1"))
43
+ EXPOSED.host = "127.0.0.1"
44
+ else if(ip.includes("localhost"))
45
+ EXPOSED.host = "localhost"
46
+
41
47
  res.json({
42
48
  success: true,
43
49
  data: EXPOSED
@@ -60,6 +60,11 @@ router.post('/attachment', upload.single('file'), (req, res) => {
60
60
  let protocol = process.env.OAC_EXPOSED_PROTOCOL || 'http';
61
61
  let host = process.env.OAC_EXPOSED_HOST || '127.0.0.1';
62
62
  if(host=="localhost") host="127.0.0.1";
63
+
64
+ const ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress;
65
+ if(host=="127.0.0.1" && ip.includes("localhost"))
66
+ host="localhost"
67
+
63
68
  let port = process.env.OAC_EXPOSED_PORT || '4000';
64
69
  deleteFiles([req.file])
65
70
  res.json({
@@ -16,7 +16,7 @@ const axios = require('axios');
16
16
 
17
17
  let SCHEMAS = {}
18
18
 
19
- const getSchema = function(format){
19
+ const getSchema = function(format, req){
20
20
  let fileContent = null;
21
21
  let filePath = null;
22
22
  let fileType = null;
@@ -25,8 +25,8 @@ const getSchema = function(format){
25
25
  filePath = 'config.shacl.ttl'; //'schema_v1.shacl.ttl';
26
26
  fileType = 'text/turtle';
27
27
  break;
28
- case 'ttl2':
29
- filePath = 'schema_v2.shacl.ttl';
28
+ case 'editing':
29
+ filePath = 'schema_editing.ttl';
30
30
  fileType = 'text/turtle';
31
31
  break;
32
32
  case 'advanced':
@@ -59,6 +59,11 @@ const getSchema = function(format){
59
59
  let protocol = process.env.OAC_EXPOSED_PROTOCOL || 'http';
60
60
  let host = process.env.OAC_EXPOSED_HOST || '127.0.0.1';
61
61
  if(host=="localhost") host="127.0.0.1";
62
+
63
+ const ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress;
64
+ if(host=="127.0.0.1" && ip.includes("localhost"))
65
+ host="localhost"
66
+
62
67
  let port = process.env.OAC_EXPOSED_PORT || '4000';
63
68
  fileContent = fileContent.replace(/OAC_EXPOSED_PROTOCOL/g, protocol);
64
69
  fileContent = fileContent.replace(/OAC_EXPOSED_HOST/g, host);
@@ -71,7 +76,7 @@ const getSchema = function(format){
71
76
  router.get('/schema/:format', (req, res) => {
72
77
  console.log(`Requesting SHACL schema in format: ${req.params.format}`);
73
78
  let format = req.params.format || 'ttl';
74
- let schema = getSchema(format);
79
+ let schema = getSchema(format, req);
75
80
  let fileContent = schema.content;
76
81
  res.setHeader('Content-Type', schema.type);
77
82
  const tempFile = tmp.fileSync({ postfix: schema.path });
@@ -107,7 +112,7 @@ router.get('/counter/:name', (req, res) => {
107
112
 
108
113
  router.post('/validate', (req, res) => {
109
114
  let turtle = req.body.turtle;
110
- let schema = getSchema('ttl2');
115
+ let schema = getSchema('editing', req);
111
116
  console.log("validate...")
112
117
  let shacl = schema.content.replace(/owl:imports/g, '#owl:imports');
113
118
  Validator.validateDataSyntax(turtle, shacl).then( (result) => {