1
+ import app from './server' ;
1
2
import express from 'express' ;
2
- import bodyParser from 'body-parser' ;
3
- import fs from 'fs' ;
4
- import swaggerUi from 'swagger-ui-express' ;
5
- import YAML from 'yamljs' ;
6
-
7
- import { createSchema , getSchemaById } from './controller/schema_controller' ;
8
3
import { createConnection } from 'typeorm' ;
9
4
import { dbConfig } from './dbconfig' ;
10
5
import { addDelegateAsRegistryDelegate } from './init' ;
6
+ import {
7
+ createSchema ,
8
+ getSchemaById ,
9
+ } from './controller/schema_controller' ;
11
10
import {
12
11
documentHashOnChain ,
13
12
getCredById ,
14
13
issueVC ,
15
14
revokeCred ,
16
15
updateCred ,
17
16
} from './controller/credential_controller' ;
18
- import cors from 'cors' ;
19
- const app = express ( ) ;
20
- export const { PORT } = process . env ;
21
-
22
- app . use ( bodyParser . json ( { limit : '5mb' } ) ) ;
23
- app . use ( express . json ( ) ) ;
24
-
25
-
26
- const allowedOrigins = [
27
- 'http://localhost:3000' ,
28
- 'http://localhost:5001' ,
29
- 'http://localhost:5108' ,
30
- 'https://studio.dhiway.com' ,
31
- 'https://markdemo.dhiway.com' ,
32
- 'https://studiodemo.dhiway.com' ,
33
- ] ;
34
-
35
-
36
- const allowedDomains = [
37
- 'localhost' ,
38
- 'dhiway.com' ,
39
- 'dway.io' ,
40
- 'cord.network' ,
41
- 'amplifyapp.com' /* For supporting quick hosting of UI */ ,
42
- ] ;
43
-
44
- app . use (
45
- cors ( {
46
- origin : function ( origin , callback ) {
47
- if ( ! origin ) return callback ( null , true ) ;
48
- let tmpOrigin = origin ;
49
-
50
- if ( origin . slice ( - 1 ) === '/' ) {
51
- tmpOrigin = origin . substring ( 0 , origin . length - 1 ) ;
52
- }
53
- if ( allowedOrigins . indexOf ( tmpOrigin ) === - 1 ) {
54
- /* Check if we should allow star/asteric */
55
- const b = tmpOrigin . split ( '/' ) [ 2 ] . split ( '.' ) ;
56
- const domain = `${ b [ b . length - 2 ] } .${ b [ b . length - 1 ] } ` ;
57
- if ( allowedDomains . indexOf ( domain ) === - 1 ) {
58
- console . log ( tmpOrigin , domain ) ;
59
- const msg = `The CORS policy for this site (${ origin } ) does not allow access from the specified Origin.` ;
60
- return callback ( new Error ( msg ) , false ) ;
61
- }
62
- }
63
- return callback ( null , true ) ;
64
- } ,
65
- optionsSuccessStatus : 200 , // For legacy browser support
66
- credentials : true ,
67
- preflightContinue : true ,
68
- methods : [ 'GET' , 'PUT' , 'POST' , 'DELETE' , 'OPTIONS' , 'HEAD' , 'PATCH' ] ,
69
- allowedHeaders : [
70
- 'Content-Type' ,
71
- 'X-UserId' ,
72
- 'Accept' ,
73
- 'Authorization' ,
74
- 'user-agent' ,
75
- 'Host' ,
76
- 'X-Forwarded-For' ,
77
- 'Upgrade' ,
78
- 'Connection' ,
79
- 'X-Content-Type-Options' ,
80
- 'Content-Security-Policy' ,
81
- 'X-Frame-Options' ,
82
- 'Strict-Transport-Security' ,
83
- ] ,
84
- } )
85
- ) ;
17
+ const {
18
+ PORT
19
+ } = process . env ;
86
20
87
21
const credentialRouter = express . Router ( { mergeParams : true } ) ;
88
22
const schemaRouter = express . Router ( { mergeParams : true } ) ;
@@ -111,9 +45,6 @@ schemaRouter.get('/:id', async (req, res) => {
111
45
return await getSchemaById ( req , res ) ;
112
46
} ) ;
113
47
114
- const openApiDocumentation = YAML . load ( './apis.yaml' ) ;
115
-
116
- app . use ( '/docs' , swaggerUi . serve , swaggerUi . setup ( openApiDocumentation ) ) ;
117
48
app . use ( '/api/v1/schema' , schemaRouter ) ;
118
49
app . use ( '/api/v1/cred' , credentialRouter ) ;
119
50
@@ -130,7 +61,6 @@ app.get('/*', async (req, res) => {
130
61
async function main ( ) {
131
62
try {
132
63
await createConnection ( dbConfig ) ;
133
-
134
64
await addDelegateAsRegistryDelegate ( ) ;
135
65
} catch ( error ) {
136
66
console . log ( 'error: ' , error ) ;
0 commit comments