-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
119 lines (94 loc) · 2.98 KB
/
index.js
File metadata and controls
119 lines (94 loc) · 2.98 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
const PORT = process.env.PORT || 8000
const express = require('express')
const bodyParser = require('body-parser');
const apicache = require('apicache')
const cors = require('cors');
const fileupload = require("express-fileupload");
let cache = apicache.middleware;
const { version } = require('./package.json');
const dotenv = require('dotenv');
dotenv.config();
// imports
const services = require('./src/services');
const entities = require('./src/api/entities');
const assets = require('./src/operations/assets');
// TODO: removed deprecated endpoints after during internal testing v1.3.0
/******************/
/******************/
/***** ENTRY ******/
/******************/
/******************/
const app = express();
// app.use(cache('1 day'));
app.use(cors());
app.use(fileupload());
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
app.get('/', (req, res) => {
res.json('Welcome to Aletheia Data API')
})
/******************/
/******************/
/****** UTILS *****/
/******************/
/******************/
/******************/
/******************/
/***** SERVICES ***/
/******************/
/******************/
/* V1 */
console.log('activating services for version: ', version);
/* Scraper */
app.get('/v1/services/scraper/:source/:category/:value', services.scraping);
/* Services */
/* DEPRECATED */
app.get('/v1/services/screenshot/:format/:width/:height', services.makeScreenshot);
/* Screenshots */
if (process.env.WEB3_STORAGE_API_KEY){
console.log('activating Web3 Storage for screenshoot service');
} else {
throw new Error('missing Web3 Storage API Key')
}
app.get('/v1/services/certified-screenshot/:width/:height', services.certScreenshot);
/* Transform CSV */
app.get(`/v1/services/transform-csv/:host/:cid`, services.getJson);
/* Search */
app.get(`/v1/services/search/:host/:cid`, services.minisearch);
/* Filecoin */
app.get(`/v1/services/filecoin/:cid`, services.filecoin);
/******************/
/******************/
/***** DATA API ***/
/* DEPRECATED */
/******************/
/* DEPRECATED */
console.log('activating Data API');
app.get(`/v1/api/:entity/getAll`, entities.getAll);
app.get(`/v2/api/:entity/getAll`, entities.getAllV2);
/******************/
/******************/
/***** OPEN API ***/
/******************/
/******************/
app.get(`/v2/open-data/:entity/getAll`, entities.getAll);
/******************/
/******************/
/***** OPERATIONS ***/
/******************/
/******************/
app.post(`/v2/ops/assets/add`, assets.add);
/******************/
/**** CAUTION *****/
/***** IMPORT *****/
/******************/
/******************/
/* DEPRECATED */
app.get(`/v1/import/:baseUrl/:startUrl`, services.importUrl);
app.get(`/v1/_import/:source/:operation`, services._import);
/* v2.0.0 */
app.get(`/v2/import/datos-abiertos/:operation`, services._import);
/******************/
/***** LISTEN PORT ******/
/******************/
app.listen(PORT, () => console.log(`CORS-enabled server running on PORT ${PORT}`))