-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
42 lines (35 loc) · 1.23 KB
/
app.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
import express from 'express';
import http from 'http';
import https from "https";
import cors from 'cors';
import ResolverDID from "./resolver.js";
import fs from "fs";
const app = express();
const resolver = new ResolverDID();
app.use( cors() );
app.use( express.json( { limit: 152428800 } ) );
app.use( express.urlencoded( { extended: false } ) );
app.use( '/:did', async( req, res, next ) => {
res.setHeader( 'Strict-Transport-Security', 'max-age=15724800; includeSubDomains' );
try {
const document = await resolver.resolve( req.params.did );
res.send( 200, JSON.stringify( document, null, 2 ) );
} catch( e ){
res.send( 500, e.message );
}
} );
const port = process.env.PORT || 80;
if( !process.env.SSL ) {
const server = http.createServer( app );
server.listen( port, () => {
console.log( 'LACChain Universal Resolver | v1.0 HTTP port', port );
} );
} else {
const privateKey = fs.readFileSync( process.env.CERT_KEY, 'utf8' );
const certificate = fs.readFileSync( process.env.CERT_CRT, 'utf8' );
const credentials = { key: privateKey, cert: certificate };
const ssl = https.createServer( credentials, app );
ssl.listen( port, '0.0.0.0', () => {
console.log( 'LACChain Universal Resolver | v1.0 HTTPS port', port );
} );
}