Skip to content

Commit

Permalink
Introduced generalized base URL
Browse files Browse the repository at this point in the history
  • Loading branch information
thehenrytsai committed Jun 28, 2024
1 parent c60648d commit 55e7c86
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ Configuration can be set using environment variables
| `DS_PORT` | Port that the server listens on | `3000` |
| `DS_MAX_RECORD_DATA_SIZE` | Maximum size for `RecordsWrite` data. use `b`, `kb`, `mb`, `gb` for value | `1gb` |
| `DS_WEBSOCKET_SERVER` | Whether to enable listening over `ws:`. values: `on`,`off` | `on` |
| `DWN_BASE_URL` | Base external URL of this DWN. Used to construct URL paths such as the `Request URI` for the Web5 Connect flow. | http://localhost |

Check failure on line 284 in README.md

View workflow job for this annotation

GitHub Actions / lint

Bare URL used

README.md:284:177 MD034/no-bare-urls Bare URL used [Context: "http://localhost"] https://github.com/DavidAnson/markdownlint/blob/v0.31.1/doc/md034.md
| `DWN_REGISTRATION_STORE_URL` | URL to use for storage of registered DIDs. Leave unset to if DWN does not require registration (ie. open for all) | unset |
| `DWN_REGISTRATION_PROOF_OF_WORK_SEED` | Seed to generate the challenge nonce from, this allows all DWN instances in a cluster to generate the same challenge. | unset |
| `DWN_REGISTRATION_PROOF_OF_WORK_ENABLED` | Require new users to complete a proof-of-work challenge | `false` |
Expand Down
13 changes: 7 additions & 6 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ export const config = {
* otherwise we fall back on the use defined `DWN_SERVER_PACKAGE_NAME` or `@web5/dwn-server`.
*/
serverName: process.env.npm_package_name || process.env.DWN_SERVER_PACKAGE_NAME || '@web5/dwn-server',

/**
* The base external URL of this DWN.
* This is used to construct URL paths such as the `Request URI` in the Web5 Connect flow.
*/
baseUrl: process.env.DWN_BASE_URL || 'http://localhost',

/**
* Used to populate the `version` and `sdkVersion` properties returned by the `/info` endpoint.
*
Expand Down Expand Up @@ -39,10 +46,4 @@ export const config = {

// log level - trace/debug/info/warn/error
logLevel: process.env.DWN_SERVER_LOG_LEVEL || 'INFO',

/**
* The base URL of the connect server excluding the port (port will be appended by using the `port` param in this config),
* this is used to construct the full Web5 Connect Request URI for the Identity Provider (wallet) to use to fetch the Web5 Connect Request object.
*/
web5ConnectServerBaseUrl: process.env.WEB5_CONNECT_SERVER_BASE_URL || 'http://localhost',
};
5 changes: 3 additions & 2 deletions src/http-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export class HttpApi {
this.registrationManager = registrationManager;
}

// setup the Web5 Connect Server
// create the Web5 Connect Server
this.web5ConnectServer = new Web5ConnectServer({
baseUrl: `${config.web5ConnectServerBaseUrl}:${config.port}`,
baseUrl: `${config.baseUrl}:${config.port}`,
});

this.#setupMiddleware();
Expand Down Expand Up @@ -320,6 +320,7 @@ export class HttpApi {
}

res.json({
url : config.baseUrl,
server : this.#packageInfo.server,
maxFileSize : config.maxRecordDataSize,
registrationRequirements : registrationRequirements,
Expand Down
3 changes: 2 additions & 1 deletion src/web5-connect/web5-connect-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export class Web5ConnectServer {

/**
* Creates a new instance of the Web5 Connect Server.
* @param params.baseUrl The the base URL of the connect server including the port, this is used to construct the full request URI.
* @param params.baseUrl The the base URL of the connect server including the port.
* This is given to the Identity Provider (wallet) to fetch the Web5 Connect Request object.
*/
public constructor({ baseUrl }: {
baseUrl: string;
Expand Down
1 change: 1 addition & 0 deletions tests/http-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ describe('http api', function () {
expect(resp.status).to.equal(200);

const info = await resp.json();
expect(info['url']).to.equal('http://localhost');
expect(info['server']).to.equal('@web5/dwn-server');
expect(info['registrationRequirements']).to.include('terms-of-service');
expect(info['registrationRequirements']).to.include(
Expand Down

0 comments on commit 55e7c86

Please sign in to comment.