Skip to content

Commit

Permalink
run server as an esm module
Browse files Browse the repository at this point in the history
  • Loading branch information
patatoid committed Mar 8, 2024
1 parent 125adcd commit ec48e65
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 60 deletions.
8 changes: 3 additions & 5 deletions controllers/Default.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict';
import * as utils from '../utils/writer.js';
import * as Service from '../service/DefaultService.js';

const utils = require('../utils/writer.js');
const Service = require('../service/DefaultService.js');

exports.resolve = function resolve (req, res) {
export const resolve = function resolve (req, res) {
const identifier = req.params['identifier'];
const accept = req.get('accept');
console.log('request: ' + identifier);
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ RUN find ./ -name "*.ts" -type f -exec sed -i -e "s/'did:key:zUC7': typeof bls12

EXPOSE 8080

CMD [ "node", "index.cjs" ]
CMD [ "npm", "start" ]
8 changes: 3 additions & 5 deletions index.cjs → index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

const http = require('http');
const express = require('express');
const Controller = require('./controllers/Default.js');
import http from 'http';
import express from 'express';
import * as Controller from './controllers/Default.js';

const serverPort = 8080;

Expand Down
109 changes: 71 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
"name": "uni-resolver-driver-did-key",
"version": "0.5.0",
"description": "Universal Resolver Driver",
"main": "index.cjs",
"main": "index.js",
"scripts": {
"prestart": "npm install",
"start": "node index.cjs"
"start": "node index.js"
},
"keywords": [
"swagger"
],
"type": "module",
"license": "Unlicense",
"private": true,
"type": "commonjs",
"dependencies": {
"@malachit/did-key-jwk-jcs-pub": "0.3.0-unstable.12",
"@malachit/did-key-jwk-jcs-pub": "0.3.0-unstable.16",
"@malachit/did-key.js": "0.3.0-unstable.14",
"@transmute/did-key-bls12381": "0.3.0-unstable.10",
"@malachit/did-key.js": "0.3.0-unstable.10",
"express": "4.18.2",
"root": "github:malach-it/did-key.js"
}
Expand Down
6 changes: 2 additions & 4 deletions service/DefaultService.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

const didKey = require('@malachit/did-key.js');
import * as didKey from '@malachit/did-key.js';

/**
* Resolve a DID or other identifier.
Expand All @@ -9,7 +7,7 @@ const didKey = require('@malachit/did-key.js');
* accept String The requested MIME type of the DID document or DID resolution result. (optional)
* returns Object
**/
exports.resolve = function(identifier,accept) {
export const resolve = function(identifier,accept) {
return new Promise(function(resolve, reject) {
didKey.resolve(identifier)
.then(function(didResolutionResult) {
Expand Down
4 changes: 2 additions & 2 deletions utils/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ var ResponsePayload = function(code, payload) {
this.payload = payload;
}

exports.respondWithCode = function(code, payload) {
export const respondWithCode = function(code, payload) {
return new ResponsePayload(code, payload);
}

var writeJson = exports.writeJson = function(response, arg1, arg2) {
export const writeJson = function(response, arg1, arg2) {
var code;
var payload;

Expand Down

0 comments on commit ec48e65

Please sign in to comment.