Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
root: true,
env: {
node: true
},
extends: [
'digitalbazaar',
'digitalbazaar/jsdoc',
'digitalbazaar/module'
],
ignorePatterns: ['node_modules/'],
rules: {
'unicorn/prefer-node-protocol': 'error'
}
};
7 changes: 0 additions & 7 deletions .eslintrc.js

This file was deleted.

33 changes: 12 additions & 21 deletions .github/workflows/main.yml → .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ jobs:
timeout-minutes: 10
strategy:
matrix:
node-version: [14.x]
node-version: [22.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand All @@ -22,18 +22,13 @@ jobs:
needs: [lint]
runs-on: ubuntu-latest
timeout-minutes: 10
services:
mongodb:
image: mongo:4.2
ports:
- 27017:27017
strategy:
matrix:
node-version: [12.x, 14.x]
node-version: [20.x, 22.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: |
Expand All @@ -47,18 +42,13 @@ jobs:
needs: [test-node]
runs-on: ubuntu-latest
timeout-minutes: 10
services:
mongodb:
image: mongo:4.2
ports:
- 27017:27017
strategy:
matrix:
node-version: [14.x]
node-version: [22.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: |
Expand All @@ -69,7 +59,8 @@ jobs:
cd test
npm run coverage-ci
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v5
with:
file: ./test/coverage/lcov.info
files: ./test/coverage/lcov.info
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
*.log
*.sw[nop]
*~
.nyc_output
.project
.settings
.vscode
TAGS
coverage
node_modules
reports
package-lock.json
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
legacy-peer-deps=true
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Bedrock HTTP API Module Template _(bedrock-module-template-http)_
# Bedrock HTTP API Module Template _(@bedrock/module-template-http)_

[![Build Status](https://img.shields.io/github/workflow/status/digitalbazaar/bedrock-module-template-http/Bedrock%20Node.js%20CI)](https://github.com/digitalbazaar/bedrock-module-template-http/actions?query=workflow%3A%22Bedrock+Node.js+CI%22)
[![NPM Version](https://img.shields.io/npm/v/bedrock-module-template-http.svg)](https://npm.im/bedrock-module-template-http)
[![Build Status](https://img.shields.io/github/actions/workflow/status/digitalbazaar/bedrock-module-temlpate-http/main.yaml)](https://github.com/digitalbazaar/bedrock-module-template-http/actions/workflows/main.yaml)
[![NPM Version](https://img.shields.io/npm/v/@bedrock/module-template-http.svg)](https://npm.im/@bedrock/module-template-http)

> A template for HTTP API modules for Bedrock applications.

Expand All @@ -25,14 +25,14 @@ TBD

## Install

- Node.js 12+ is required.
- Node.js 20+ is required.

### NPM

To install via NPM:

```
npm install --save bedrock-module-template-http
npm install --save @bedrock/module-template-http
```

### Development
Expand Down
9 changes: 4 additions & 5 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/*!
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
* Copyright (c) 2025 Digital Bazaar, Inc. All rights reserved.
*/
import bedrock from 'bedrock';
import * as bedrock from '@bedrock/core';
const {config} = bedrock;

const namespace = 'module-template-http';
export const namespace = 'module-template-http';
const cfg = config[namespace] = {};

const basePath = '/foo';
cfg.routes = {
basePath
basePath: '/foo'
};
25 changes: 19 additions & 6 deletions lib/http.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
/*!
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
* Copyright (c) 2025 Digital Bazaar, Inc. All rights reserved.
*/
import {asyncHandler} from 'bedrock-express';
import bedrock from 'bedrock';
const {config} = bedrock;
import * as bedrock from '@bedrock/core';
import {asyncHandler} from '@bedrock/express';
import {example} from '../schemas/bedrock-template.js';
import {namespace} from './config.js';
import {createValidateMiddleware as validate} from '@bedrock/validation';

const {util: {BedrockError}} = bedrock;

bedrock.events.on('bedrock-express.configure.routes', app => {
const {routes} = config['module-template-http'];
const {config} = bedrock;
const {routes} = config[namespace];

app.post(
routes.basePath,
validate({bodySchema: example}),
asyncHandler(async (/*req, res*/) => {
}));
throw new BedrockError(
'Not implemented.', {
name: 'NotFoundError',
details: {httpStatusCode: 501, public: true}
});
})
);
});
9 changes: 4 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/*!
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
* Copyright (c) 2025 Digital Bazaar, Inc. All rights reserved.
*/
'use strict';
import '@bedrock/express';

// translate `main.js` to CommonJS
require = require('esm')(module);
module.exports = require('./main.js');
import './config.js';
import './http.js';
7 changes: 7 additions & 0 deletions lib/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*!
* Copyright (c) 2025 Digital Bazaar, Inc. All rights reserved.
*/
import {loggers} from '@bedrock/core';
import {namespace} from './config.js';

export const logger = loggers.get('app').child(namespace);
7 changes: 0 additions & 7 deletions lib/main.js

This file was deleted.

25 changes: 15 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"name": "bedrock-module-template-http",
"name": "@bedrock/module-template-http",
"version": "0.0.1-0",
"type": "module",
"description": "Bedrock HTTP API",
"main": "./lib",
"main": "./lib/index.js",
"files": [
"lib/**/*.js",
"schemas/**/*.js"
],
"scripts": {
"lint": "eslint ."
},
Expand All @@ -22,21 +27,21 @@
"url": "https://github.com/digitalbazaar/bedrock-module-template-http/issues"
},
"homepage": "https://github.com/digitalbazaar/bedrock-module-template-http",
"dependencies": {
"esm": "^3.2.25"
},
"peerDependencies": {
"bedrock": "^4.4.0",
"bedrock-express": "^5.0.1"
"@bedrock/core": "^6.3.0",
"@bedrock/express": "^8.3.2",
"@bedrock/validation": "^7.1.1"
},
"directories": {
"lib": "./lib"
},
"devDependencies": {
"eslint": "^7.32.0",
"eslint-config-digitalbazaar": "^2.8.0"
"eslint": "^8.57.1",
"eslint-config-digitalbazaar": "^5.2.0",
"eslint-plugin-jsdoc": "^51.4.1",
"eslint-plugin-unicorn": "^56.0.1"
},
"engines": {
"node": ">=12"
"node": ">=20"
}
}
14 changes: 14 additions & 0 deletions schemas/bedrock-template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*!
* Copyright (c) 2025 Digital Bazaar, Inc. All rights reserved.
*/
import {schemas} from '@bedrock/validation';

export const example = {
title: 'Example',
type: 'object',
required: ['id'],
additionalProperties: false,
properties: {
id: schemas.identifier()
}
};
9 changes: 0 additions & 9 deletions test/mocha/.eslintrc

This file was deleted.

9 changes: 9 additions & 0 deletions test/mocha/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
env: {
mocha: true
},
globals: {
assertNoError: true,
should: true
}
}
3 changes: 1 addition & 2 deletions test/mocha/10-api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
* Copyright (c) 2025 Digital Bazaar, Inc. All rights reserved.
*/

describe('api', () => {
it('should work');
});
40 changes: 23 additions & 17 deletions test/package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
{
"name": "bedrock-module-template-http-test",
"version": "0.0.1-0",
"name": "@bedrock/module-template-http-test",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"test": "node --preserve-symlinks test.js test",
"coverage": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text-summary npm test",
"coverage-ci": "cross-env NODE_ENV=test nyc --reporter=lcovonly npm test",
"coverage-report": "nyc report"
"coverage": "cross-env NODE_ENV=test c8 --reporter=lcov --reporter=text-summary npm test",
"coverage-ci": "cross-env NODE_ENV=test c8 --reporter=lcovonly npm test",
"coverage-report": "c8 report"
},
"dependencies": {
"bedrock": "^4.4.0",
"bedrock-express": "^5.0.1",
"bedrock-https-agent": "^2.1.0",
"bedrock-module-template-http": "file:..",
"bedrock-mongodb": "^8.4.0",
"bedrock-server": "^3.0.0",
"bedrock-test": "^5.4.0",
"cross-env": "^7.0.3",
"nyc": "^15.1.0"
"@bedrock/core": "^6.3.0",
"@bedrock/express": "^8.3.2",
"@bedrock/https-agent": "^4.1.0",
"@bedrock/module-template-http": "file:..",
"@bedrock/server": "^5.1.0",
"@bedrock/test": "^8.2.0",
"@bedrock/validation": "^7.1.1",
"c8": "^10.1.3",
"cross-env": "^7.0.3"
},
"nyc": {
"c8": {
"excludeNodeModules": false,
"include": [
"node_modules/bedrock-module-template-http/**"
"node_modules/@bedrock/module-template-http/**"
],
"exclude": [
"node_modules/bedrock-module-template-http/node_modules/**"
"node_modules/@bedrock/module-template-http/node_modules/**"
],
"reporter": [
"lcov",
"text-summary",
"text"
]
}
}
15 changes: 4 additions & 11 deletions test/test.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
/*
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
* Copyright (c) 2025 Digital Bazaar, Inc. All rights reserved..
*/
'use strict';
import {config} from '@bedrock/core';
import path from 'node:path';

const {config} = require('bedrock');
const path = require('path');

// MongoDB
config.mongodb.name = 'bedrock_module_template_http_test';
config.mongodb.dropCollections.onInit = true;
config.mongodb.dropCollections.collections = [];

config.mocha.tests.push(path.join(__dirname, 'mocha'));
config.mocha.tests.push(path.join(import.meta.dirname, 'mocha'));

// allow self-signed certs in test framework
config['https-agent'].rejectUnauthorized = false;
Loading