To install @nuz/registry package, you just run below command:
# with npm
$ npm install @nuz/registry
# or yarn
$ yarn add @nuz/registry
Create a registry server:
const registry = require('@nuz/registry');
(async function main() {
const server = new registry.Server({
key: 'secret-key',
db: {
type: 'mongodb',
url: 'mongodb://localhost:27017/registry',
},
});
await server.prepare();
server.listen(4004);
})();
Example using express
middlewares:
(async function main() {
const server = new registry.Server(...);
await server.middlewares(async (app) => {
app.use(morgan(':method :url :status :res[content-length] - :response-time ms'));
app.use(cors());
});
await server.prepare();
})();
See simple registry server example.
Create a server
new registry.Server(
// ServerOptions
)
export interface ServerOptions {
key: string
db: DBOptions
https?: boolean | HttpsConfig
compression?: boolean | compression.CompressionOptions
serverless?: ServerlessOptions
}
This is master key, using to verify before handle token
.
DBOptions
is object having
const { type, ...rest } = db
type
is set database want to used. Currently, onlymongodb
is supported....rest
is pass all other values to constructor while create DB class.
If type is mongodb
please add url
as MongoDB url.
Default is false
.
Provide https config for your registry server. If set is true
, @nuz/registry will auto generate self certificate to use https connect method.
export interface HttpsConfig {
key: Buffer | string
cert: Buffer | string
}
@nuz/registry use spdy to handle on https and http2.
Note: Please only use true
for localhost
, in development mode. In proudction, please provide your certificate!
Default is true
.
@nuz/registry use compression to compress. Set is true
will use default with default config, you can also pass compression.CompressionOptions
!
Pass options to route handler.
Tip: fetch
route is support cache, you ca use it by config:
serverless: {
...
fetch: {
cacheTime: 300000, // 5m, cache time
prepareTime: 60000, // 1m, prepare time
}
}
Edit Authorization, set value is key
field in ServerOptions
: