update
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
process.env.CLI_CALL = 'true';
|
process.env.CLI_CALL = 'true';
|
||||||
require('@gitzone/tsrun');
|
import '@git.zone/tsrun';
|
||||||
const cliTool = require('./ts/index');
|
const cliTool = await import('./ts/index.js');
|
||||||
cliTool.runCli();
|
cliTool.runCli();
|
||||||
|
|||||||
56
package.json
56
package.json
@@ -2,10 +2,11 @@
|
|||||||
"name": "npmcdn",
|
"name": "npmcdn",
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"description": "a cdn using npm as source",
|
"description": "a cdn using npm as source",
|
||||||
|
"type": "module",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"author": "Lossless GmbH",
|
"author": "Task Venture Capital GmbH",
|
||||||
"license": "UNLICENSED",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"start": "(node --max_old_space_size=100 ./cli.js)",
|
"start": "(node --max_old_space_size=100 ./cli.js)",
|
||||||
@@ -13,38 +14,29 @@
|
|||||||
"build": "(tsbuild --web)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.17",
|
"@git.zone/tsbuild": "^4.1.0",
|
||||||
"@gitzone/tsrun": "^1.2.8",
|
"@git.zone/tsrun": "^2.0.1",
|
||||||
"@gitzone/tstest": "^1.0.28",
|
"@git.zone/tstest": "^3.1.4",
|
||||||
"@gitzone/tswatch": "^1.0.30",
|
"@push.rocks/smartnetwork": "^4.4.0",
|
||||||
"@pushrocks/tapbundle": "^3.0.13",
|
"@push.rocks/smartrequest": "^5.0.1"
|
||||||
"tslint": "^5.20.0",
|
|
||||||
"tslint-config-prettier": "^1.18.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@losslessone_private/lole-serviceserver": "^1.0.24",
|
"@losslessone_private/lole-serviceserver": "^1.0.54",
|
||||||
"@pushrocks/smartstate": "^1.0.14",
|
"@push.rocks/projectinfo": "^5.0.2",
|
||||||
"@pushrocks/qenv": "^4.0.10",
|
"@push.rocks/qenv": "^6.1.0",
|
||||||
"@pushrocks/smartdata": "^4.0.12",
|
"@push.rocks/smartdelay": "^3.0.5",
|
||||||
"@pushrocks/projectinfo": "^4.0.5",
|
"@push.rocks/smartfile": "^11.1.3",
|
||||||
"@pushrocks/smartdelay": "^2.0.13",
|
"@push.rocks/smartmarkdown": "^3.0.3",
|
||||||
"@pushrocks/smartfile": "^8.0.10",
|
"@push.rocks/smartmime": "^2.0.4",
|
||||||
"@pushrocks/smartmarkdown": "^2.0.6",
|
"@push.rocks/smartnpm": "^2.0.6",
|
||||||
"@pushrocks/smartmime": "^1.0.5",
|
"@push.rocks/smartpromise": "^4.2.3",
|
||||||
"@pushrocks/smartnpm": "^1.0.39",
|
"@push.rocks/smarttime": "^4.1.1",
|
||||||
"@pushrocks/smartpromise": "^3.1.6",
|
"@types/compression": "^1.8.1",
|
||||||
"@pushrocks/smarttime": "^3.0.38",
|
"@types/express": "^5.0.6",
|
||||||
"@pushrocks/tapbundle": "^3.2.14",
|
"compression": "^1.8.1",
|
||||||
"@types/autocannon": "^4.1.1",
|
"express": "^4.22.1",
|
||||||
"@types/compression": "^1.7.2",
|
"lit-ntml": "^4.0.2",
|
||||||
"@types/express": "^4.17.13",
|
"prom-client": "^15.1.3"
|
||||||
"@types/splunk-logging": "^0.9.2",
|
|
||||||
"compression": "^1.7.4",
|
|
||||||
"express": "^4.17.1",
|
|
||||||
"lit-ntml": "^2.20.0",
|
|
||||||
"prom-client": "^13.2.0",
|
|
||||||
"splunk-logging": "^0.11.1",
|
|
||||||
"tty-table": "^4.1.3"
|
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
|
|||||||
8906
pnpm-lock.yaml
generated
Normal file
8906
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
184
readme.md
184
readme.md
@@ -1,34 +1,164 @@
|
|||||||
# @losslessone/services/servezone/npmcdn
|
# npmcdn
|
||||||
undefined variable
|
|
||||||
|
|
||||||
## Availabililty and Links
|
> 🚀 A blazing-fast CDN that serves files directly from npm packages
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/npmcdn)
|
|
||||||
* [gitlab.com (source)](https://gitlab.com/losslessone/services/servezone/npmcdn)
|
|
||||||
* [github.com (source mirror)](https://github.com/losslessone/services/servezone/npmcdn)
|
|
||||||
* [docs (typedoc)](https://losslessone/services/servezone.gitlab.io/npmcdn/)
|
|
||||||
|
|
||||||
## Status for master
|
`npmcdn` is a lightweight, TypeScript-powered CDN server that allows you to serve specific files from npm packages. Think of it as your own private unpkg/jsdelivr, but with fine-grained control over which packages are accessible.
|
||||||
|
|
||||||
Status Category | Status Badge
|
## Issue Reporting and Security
|
||||||
-- | --
|
|
||||||
GitLab Pipelines | [](https://lossless.cloud)
|
|
||||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
|
||||||
npm | [](https://lossless.cloud)
|
|
||||||
Snyk | [](https://lossless.cloud)
|
|
||||||
TypeScript Support | [](https://lossless.cloud)
|
|
||||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
Code Style | [](https://lossless.cloud)
|
|
||||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
|
||||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
|
||||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
|
||||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
|
||||||
|
|
||||||
## Usage
|
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
|
||||||
|
|
||||||
Use TypeScript for best in class intellisense
|
## ✨ Features
|
||||||
For further information read the linked docs at the top of this readme.
|
|
||||||
|
|
||||||
> UNLICENSED licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
- **📦 Package Allowlisting** - Only serve files from packages you explicitly approve
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
- **🔢 Version Support** - Request specific versions, version ranges, or dist-tags
|
||||||
|
- **⚡ Smart Caching** - Built-in cache headers for optimal performance
|
||||||
|
- **🗜️ Compression** - Automatic gzip compression for smaller payloads
|
||||||
|
- **🔍 Peek Mode** - Dev mode includes a UI to browse available packages and files
|
||||||
|
- **📄 MIME Type Detection** - Automatic content-type detection for served files
|
||||||
|
- **🌐 CORS Ready** - Cross-origin requests supported out of the box
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
## 📦 Installation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm add npmcdn
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🚀 Quick Start
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { UiPublicServer } from 'npmcdn';
|
||||||
|
|
||||||
|
const server = new UiPublicServer({
|
||||||
|
port: 3000,
|
||||||
|
npmRegistryUrl: 'https://registry.npmjs.org/',
|
||||||
|
allowedPackages: [
|
||||||
|
'@push.rocks/smartfile',
|
||||||
|
'@push.rocks/smartpromise',
|
||||||
|
// Add more packages as needed
|
||||||
|
],
|
||||||
|
packageBaseDirectory: './', // Path within packages to serve from
|
||||||
|
mode: 'dev', // 'dev' or 'prod'
|
||||||
|
});
|
||||||
|
|
||||||
|
await server.startServer();
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📡 API Endpoints
|
||||||
|
|
||||||
|
Once running, access files using this URL pattern:
|
||||||
|
|
||||||
|
```
|
||||||
|
http://localhost:3000/@scope/package-name/path/to/file.js?version=1.2.3
|
||||||
|
```
|
||||||
|
|
||||||
|
### Query Parameters
|
||||||
|
|
||||||
|
| Parameter | Description | Example |
|
||||||
|
|-----------|-------------|---------|
|
||||||
|
| `version` | Semver version or range | `1.2.3`, `^1.0.0`, `2.x.x` |
|
||||||
|
| `disttag` | Dist tag name | `latest`, `beta`, `next` |
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Get the readme from latest version
|
||||||
|
curl http://localhost:3000/@push.rocks/smartfile/readme.md
|
||||||
|
|
||||||
|
# Get package.json from specific version
|
||||||
|
curl http://localhost:3000/@push.rocks/smartfile/package.json?version=10.0.0
|
||||||
|
|
||||||
|
# Get a file using version range
|
||||||
|
curl http://localhost:3000/@push.rocks/smartfile/dist_ts/index.js?version=11.x.x
|
||||||
|
```
|
||||||
|
|
||||||
|
## ⚙️ Configuration Options
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
interface IPublicServerOptions {
|
||||||
|
port?: number; // Server port (default: 8080)
|
||||||
|
npmRegistryUrl?: string; // npm registry URL (default: https://registry.npmjs.org)
|
||||||
|
allowedPackages?: string[]; // Array of allowed package names
|
||||||
|
packageBaseDirectory?: string; // Base path within packages (default: './')
|
||||||
|
mode: 'dev' | 'prod'; // Server mode
|
||||||
|
log?: boolean; // Enable request logging (default: true)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔧 Dev Mode Features
|
||||||
|
|
||||||
|
When running in `dev` mode, you get access to additional endpoints:
|
||||||
|
|
||||||
|
- **`/peek/`** - Browse all allowlisted packages and their files
|
||||||
|
- **`/readme/`** - View the server's readme as HTML
|
||||||
|
|
||||||
|
These endpoints help you explore what's available without needing to know exact file paths.
|
||||||
|
|
||||||
|
## 🏗️ Architecture
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────────────────────────────────────────────┐
|
||||||
|
│ Client Request │
|
||||||
|
│ GET /@scope/package/path/to/file.js?version=1.2.3 │
|
||||||
|
└─────────────────────────────────────────────────────────┘
|
||||||
|
│
|
||||||
|
▼
|
||||||
|
┌─────────────────────────────────────────────────────────┐
|
||||||
|
│ UiPublicServer │
|
||||||
|
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────┐ │
|
||||||
|
│ │ Allowlist │ │ Cache │ │ GZIP │ │
|
||||||
|
│ │ Check │──│ Layer │──│ Compression │ │
|
||||||
|
│ └─────────────┘ └─────────────┘ └─────────────────┘ │
|
||||||
|
└─────────────────────────────────────────────────────────┘
|
||||||
|
│
|
||||||
|
▼
|
||||||
|
┌─────────────────────────────────────────────────────────┐
|
||||||
|
│ npm Registry │
|
||||||
|
│ (fetch package tarball) │
|
||||||
|
└─────────────────────────────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔒 Security
|
||||||
|
|
||||||
|
- **Allowlisting** - Only explicitly allowed packages can be served
|
||||||
|
- **Path Validation** - Requests are validated against the allowed package base directory
|
||||||
|
- **No Arbitrary Execution** - The server only serves static files, no code execution
|
||||||
|
|
||||||
|
## 🛠️ Use Cases
|
||||||
|
|
||||||
|
- **Microservices** - Serve shared frontend assets across multiple services
|
||||||
|
- **Internal CDN** - Host internal packages for your organization
|
||||||
|
- **Development** - Quick access to npm package files during development
|
||||||
|
- **Documentation** - Serve package documentation directly
|
||||||
|
|
||||||
|
## 📊 Response Headers
|
||||||
|
|
||||||
|
The server sets appropriate headers for caching and content delivery:
|
||||||
|
|
||||||
|
| Header | Value |
|
||||||
|
|--------|-------|
|
||||||
|
| `content-type` | Detected MIME type |
|
||||||
|
| `content-length` | File size in bytes |
|
||||||
|
| `cache-control` | `max-age` based on version specificity |
|
||||||
|
| `access-control-allow-origin` | `*` (configurable) |
|
||||||
|
|
||||||
|
## License and Legal Information
|
||||||
|
|
||||||
|
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
|
||||||
|
|
||||||
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
### Trademarks
|
||||||
|
|
||||||
|
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
|
||||||
|
|
||||||
|
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
|
||||||
|
|
||||||
|
### Company Information
|
||||||
|
|
||||||
|
Task Venture Capital GmbH
|
||||||
|
Registered at District Court Bremen HRB 35230 HB, Germany
|
||||||
|
|
||||||
|
For any legal inquiries or further information, please contact us via email at hello@task.vc.
|
||||||
|
|
||||||
|
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { UiPublicServer } from '../ts';
|
import { UiPublicServer } from '../ts/index.js';
|
||||||
|
|
||||||
export const defaultPublicServer = new UiPublicServer({
|
export const defaultPublicServer = new UiPublicServer({
|
||||||
port: 3000,
|
port: 3000,
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||||
|
|
||||||
import * as uiPublicServer from '../ts/npm-publicserver.classes.uipublicserver';
|
import * as uiPublicServer from '../ts/npm-publicserver.classes.uipublicserver.js';
|
||||||
import * as smartnetwork from '@pushrocks/smartnetwork';
|
import * as smartnetwork from '@push.rocks/smartnetwork';
|
||||||
import * as smartrequest from '@pushrocks/smartrequest';
|
import { SmartRequest } from '@push.rocks/smartrequest';
|
||||||
|
|
||||||
const plugins = {
|
const plugins = {
|
||||||
smartnetwork,
|
smartnetwork,
|
||||||
smartrequest,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let testserverInstance: uiPublicServer.UiPublicServer;
|
let testserverInstance: uiPublicServer.UiPublicServer;
|
||||||
@@ -18,7 +17,7 @@ tap.test('should create an instance of PublicServer', async () => {
|
|||||||
allowedPackages: ['@pushrocks/smartfile'],
|
allowedPackages: ['@pushrocks/smartfile'],
|
||||||
mode: 'prod',
|
mode: 'prod',
|
||||||
});
|
});
|
||||||
expect(testserverInstance).to.be.instanceOf(uiPublicServer.UiPublicServer);
|
expect(testserverInstance).toBeInstanceOf(uiPublicServer.UiPublicServer);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should start the server', async () => {
|
tap.test('should start the server', async () => {
|
||||||
@@ -26,8 +25,8 @@ tap.test('should start the server', async () => {
|
|||||||
const result1 = await smartnetworkInstance.isLocalPortUnused(3000);
|
const result1 = await smartnetworkInstance.isLocalPortUnused(3000);
|
||||||
await testserverInstance.startServer();
|
await testserverInstance.startServer();
|
||||||
const result2 = await smartnetworkInstance.isLocalPortUnused(3000);
|
const result2 = await smartnetworkInstance.isLocalPortUnused(3000);
|
||||||
expect(result1).to.be.true;
|
expect(result1).toBeTrue();
|
||||||
expect(result2).to.be.false;
|
expect(result2).toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.skip.test('optional manual testing', async (toolsArg) => {
|
tap.skip.test('optional manual testing', async (toolsArg) => {
|
||||||
@@ -35,65 +34,53 @@ tap.skip.test('optional manual testing', async (toolsArg) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should NOT deliver a file for a malformed org', async () => {
|
tap.test('should NOT deliver a file for a malformed org', async () => {
|
||||||
const response = await plugins.smartrequest.request('http://localhost:3000/someorg/somemodule', {
|
const response = await SmartRequest.create()
|
||||||
method: 'GET',
|
.url('http://localhost:3000/someorg/somemodule')
|
||||||
});
|
.get();
|
||||||
console.log(response.body);
|
const body = await response.text();
|
||||||
expect(response.body).to.equal('npmorg "someorg" must start with @');
|
console.log(body);
|
||||||
|
expect(body).toEqual('npmorg "someorg" must start with @');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should NOT deliver a file for a nonexisting file', async () => {
|
tap.test('should NOT deliver a file for a nonexisting file', async () => {
|
||||||
const response = await plugins.smartrequest.request(
|
const response = await SmartRequest.create()
|
||||||
'http://localhost:3000/@pushrocks/smartfile/readme2.md',
|
.url('http://localhost:3000/@pushrocks/smartfile/readme2.md')
|
||||||
{
|
.get();
|
||||||
method: 'GET',
|
const body = await response.text();
|
||||||
}
|
console.log(body);
|
||||||
);
|
expect(body.includes('@pushrocks/smartfile@ does not have a file at')).toBeTrue();
|
||||||
console.log(response.body);
|
|
||||||
expect(response.body.includes('@pushrocks/smartfile@ does not have a file at')).to.be.true;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should deliver a file for an existing file', async () => {
|
tap.test('should deliver a file for an existing file', async () => {
|
||||||
const response = await plugins.smartrequest.request(
|
const response = await SmartRequest.create()
|
||||||
'http://localhost:3000/@pushrocks/smartfile/readme.md',
|
.url('http://localhost:3000/@pushrocks/smartfile/readme.md')
|
||||||
{
|
.get();
|
||||||
method: 'GET',
|
const body = await response.text();
|
||||||
}
|
expect(body.startsWith('# @pushrocks/smartfile')).toBeTrue();
|
||||||
);
|
|
||||||
expect(response.body.startsWith('# @pushrocks/smartfile')).to.be.true;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should deliver different versions', async () => {
|
tap.test('should deliver different versions', async () => {
|
||||||
const response = await plugins.smartrequest.request(
|
const response = await SmartRequest.create()
|
||||||
'http://localhost:3000/@pushrocks/smartfile/package.json?version=7',
|
.url('http://localhost:3000/@pushrocks/smartfile/package.json?version=7')
|
||||||
{
|
.get();
|
||||||
method: 'GET',
|
const packageJson = await response.json();
|
||||||
}
|
expect(packageJson.version.startsWith('7')).toBeTrue();
|
||||||
);
|
|
||||||
const packageJson = response.body;
|
|
||||||
expect(packageJson.version.startsWith('7')).to.be.true;
|
|
||||||
|
|
||||||
const response2 = await plugins.smartrequest.request(
|
const response2 = await SmartRequest.create()
|
||||||
'http://localhost:3000/@pushrocks/smartfile/package.json?version=8.x.x',
|
.url('http://localhost:3000/@pushrocks/smartfile/package.json?version=8.x.x')
|
||||||
{
|
.get();
|
||||||
method: 'GET',
|
const packageJson2 = await response2.json();
|
||||||
}
|
expect(packageJson2.version.startsWith('8')).toBeTrue();
|
||||||
);
|
|
||||||
const packageJson2 = response2.body;
|
|
||||||
expect(packageJson2.version.startsWith('8')).to.be.true;
|
|
||||||
|
|
||||||
const response3 = await plugins.smartrequest.request(
|
const response3 = await SmartRequest.create()
|
||||||
'http://localhost:3000/@pushrocks/smartfile/package.json?version=6.0.6',
|
.url('http://localhost:3000/@pushrocks/smartfile/package.json?version=6.0.6')
|
||||||
{
|
.get();
|
||||||
method: 'GET',
|
const packageJson3 = await response3.json();
|
||||||
}
|
expect(packageJson3.version).toEqual('6.0.6');
|
||||||
);
|
|
||||||
const packageJson3 = response3.body;
|
|
||||||
expect(packageJson3.version).to.equal('6.0.6');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should stop the server', async () => {
|
tap.test('should stop the server', async () => {
|
||||||
await testserverInstance.stopServer();
|
await testserverInstance.stopServer();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
export default tap.start();
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
export * from './npm-publicserver.classes.uipublicserver';
|
export * from './npm-publicserver.classes.uipublicserver.js';
|
||||||
|
|
||||||
import { UiPublicServer } from '.';
|
import { UiPublicServer } from './npm-publicserver.classes.uipublicserver.js';
|
||||||
|
|
||||||
process.env.UIP_ENV = process.env.BACKEND_URL.includes('develop-backend') ? 'dev' : 'prod';
|
process.env.UIP_ENV = process.env.BACKEND_URL?.includes('develop-backend') ? 'dev' : 'prod';
|
||||||
|
|
||||||
export const defaultPublicServer = new UiPublicServer({
|
export const defaultPublicServer = new UiPublicServer({
|
||||||
port: 3000,
|
port: 3000,
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
import * as plugins from './plugins';
|
|
||||||
|
|
||||||
export const logger = new plugins.splunkLogging.Logger({
|
|
||||||
token: '',
|
|
||||||
});
|
|
||||||
|
|
||||||
logger.send({
|
|
||||||
message: {
|
|
||||||
package: '',
|
|
||||||
subFolder: '',
|
|
||||||
filePath: '',
|
|
||||||
status: 200,
|
|
||||||
},
|
|
||||||
severity: 'info',
|
|
||||||
metadata: {
|
|
||||||
host: 'ui-publicserver',
|
|
||||||
source: 'nodejs',
|
|
||||||
sourcetype: 'process',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as interfaces from './interfaces';
|
import * as interfaces from './interfaces.js';
|
||||||
import * as plugins from './plugins';
|
import * as plugins from './plugins.js';
|
||||||
import * as paths from './paths';
|
import * as paths from './paths.js';
|
||||||
import * as ntml from './ntml';
|
import * as ntml from './ntml/index.js';
|
||||||
|
|
||||||
export interface IPublicServerOptions {
|
export interface IPublicServerOptions {
|
||||||
packageBaseDirectory?: string;
|
packageBaseDirectory?: string;
|
||||||
@@ -17,9 +17,7 @@ export interface IPublicServerOptions {
|
|||||||
*/
|
*/
|
||||||
export class UiPublicServer {
|
export class UiPublicServer {
|
||||||
public projectinfo = new plugins.projectinfo.ProjectinfoNpm(paths.packageDir);
|
public projectinfo = new plugins.projectinfo.ProjectinfoNpm(paths.packageDir);
|
||||||
public readme = new plugins.smartmarkdown.SmartMarkdown().markdownToHtml(
|
public readme: string;
|
||||||
plugins.smartfile.fs.toStringSync(plugins.path.join(paths.packageDir, 'readme.md'))
|
|
||||||
);
|
|
||||||
public startedAt: string;
|
public startedAt: string;
|
||||||
private server: plugins.http.Server;
|
private server: plugins.http.Server;
|
||||||
private npmRegistry: plugins.smartnpm.NpmRegistry;
|
private npmRegistry: plugins.smartnpm.NpmRegistry;
|
||||||
@@ -53,11 +51,24 @@ export class UiPublicServer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initializes the readme content
|
||||||
|
*/
|
||||||
|
private async initReadme(): Promise<void> {
|
||||||
|
const readmePath = plugins.path.join(paths.packageDir, 'readme.md');
|
||||||
|
const readmeContent = await plugins.smartfile.fs.toStringSync(readmePath);
|
||||||
|
this.readme = await plugins.smartmarkdown.SmartMarkdown.easyMarkdownToHtml(readmeContent);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* starts the server
|
* starts the server
|
||||||
*/
|
*/
|
||||||
public async startServer() {
|
public async startServer() {
|
||||||
console.log('starting the uipublicserver');
|
console.log('starting the uipublicserver');
|
||||||
|
|
||||||
|
// Initialize readme
|
||||||
|
await this.initReadme();
|
||||||
|
|
||||||
const done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
const expressApplication = plugins.express();
|
const expressApplication = plugins.express();
|
||||||
|
|
||||||
@@ -235,7 +246,7 @@ export class UiPublicServer {
|
|||||||
|
|
||||||
const requestDescriptor = `${packageName}/${filePath}/${distTag}/${version}`;
|
const requestDescriptor = `${packageName}/${filePath}/${distTag}/${version}`;
|
||||||
|
|
||||||
let smartfile: plugins.smartfile.Smartfile;
|
let smartfile: plugins.smartfile.SmartFile;
|
||||||
|
|
||||||
// protect against parallel requests
|
// protect against parallel requests
|
||||||
if (this.requestMap[requestDescriptor]) {
|
if (this.requestMap[requestDescriptor]) {
|
||||||
@@ -268,6 +279,10 @@ export class UiPublicServer {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Detect mime type from buffer
|
||||||
|
const mimeResult = await plugins.smartmime.detectMimeType({ buffer: smartfile.contentBuffer });
|
||||||
|
const contentType = mimeResult?.mime || 'application/octet-stream';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
headers: {
|
headers: {
|
||||||
'cache-control': `max-age=${
|
'cache-control': `max-age=${
|
||||||
@@ -276,7 +291,7 @@ export class UiPublicServer {
|
|||||||
: plugins.smarttime.getMilliSecondsFromUnits({ days: 1 })) / 1000
|
: plugins.smarttime.getMilliSecondsFromUnits({ days: 1 })) / 1000
|
||||||
}`,
|
}`,
|
||||||
'content-length': smartfile.contentBuffer.length.toString(),
|
'content-length': smartfile.contentBuffer.length.toString(),
|
||||||
'content-type': plugins.smartmime.detectMimeType(smartfile.path),
|
'content-type': contentType,
|
||||||
},
|
},
|
||||||
status: 200,
|
status: 200,
|
||||||
body: smartfile.contentBuffer,
|
body: smartfile.contentBuffer,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { UiPublicServer } from '../npm-publicserver.classes.uipublicserver';
|
import type { UiPublicServer } from '../npm-publicserver.classes.uipublicserver.js';
|
||||||
import * as plugins from '../plugins';
|
import * as plugins from '../plugins.js';
|
||||||
|
|
||||||
export const getBody = async (uipublicServerArg: UiPublicServer, contentArg: string | string[]) => {
|
export const getBody = async (uipublicServerArg: UiPublicServer, contentArg: string | string[]) => {
|
||||||
return await plugins.litNtml.html`
|
return await plugins.litNtml.html`
|
||||||
<head></head>
|
<head></head>
|
||||||
@@ -50,7 +51,7 @@ export const getBody = async (uipublicServerArg: UiPublicServer, contentArg: str
|
|||||||
</div>
|
</div>
|
||||||
${contentArg}
|
${contentArg}
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
UiPublicServer v${uipublicServerArg.projectinfo.version} |
|
UiPublicServer v${uipublicServerArg.projectinfo.version} |
|
||||||
running since ${uipublicServerArg.startedAt} |
|
running since ${uipublicServerArg.startedAt} |
|
||||||
<a href="https://lossless.gmbh" target="_blank">Legal Info</a></div>
|
<a href="https://lossless.gmbh" target="_blank">Legal Info</a></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
export * from './body';
|
export * from './body.js';
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
import * as plugins from './plugins';
|
import * as plugins from './plugins.js';
|
||||||
|
|
||||||
export const packageDir = plugins.path.join(__dirname, '../');
|
export const packageDir = plugins.path.join(import.meta.dirname, '../');
|
||||||
|
|||||||
@@ -5,15 +5,15 @@ import * as path from 'path';
|
|||||||
|
|
||||||
export { http, url, path };
|
export { http, url, path };
|
||||||
|
|
||||||
// @pushrocks scope (maintained by Lossless GmbH)
|
// @push.rocks scope
|
||||||
import * as projectinfo from '@pushrocks/projectinfo';
|
import * as projectinfo from '@push.rocks/projectinfo';
|
||||||
import * as smartdelay from '@pushrocks/smartdelay';
|
import * as smartdelay from '@push.rocks/smartdelay';
|
||||||
import * as smartfile from '@pushrocks/smartfile';
|
import * as smartfile from '@push.rocks/smartfile';
|
||||||
import * as smartmime from '@pushrocks/smartmime';
|
import * as smartmime from '@push.rocks/smartmime';
|
||||||
import * as smartmarkdown from '@pushrocks/smartmarkdown';
|
import * as smartmarkdown from '@push.rocks/smartmarkdown';
|
||||||
import * as smartnpm from '@pushrocks/smartnpm';
|
import * as smartnpm from '@push.rocks/smartnpm';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@push.rocks/smartpromise';
|
||||||
import * as smarttime from '@pushrocks/smarttime';
|
import * as smarttime from '@push.rocks/smarttime';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
projectinfo,
|
projectinfo,
|
||||||
@@ -31,6 +31,5 @@ import compression from 'compression';
|
|||||||
import express from 'express';
|
import express from 'express';
|
||||||
import * as litNtml from 'lit-ntml';
|
import * as litNtml from 'lit-ntml';
|
||||||
import * as promClient from 'prom-client';
|
import * as promClient from 'prom-client';
|
||||||
import splunkLogging from 'splunk-logging';
|
|
||||||
|
|
||||||
export { compression, express, litNtml, promClient, splunkLogging };
|
export { compression, express, litNtml, promClient };
|
||||||
|
|||||||
12
tsconfig.json
Normal file
12
tsconfig.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "NodeNext",
|
||||||
|
"moduleResolution": "NodeNext",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"verbatimModuleSyntax": true
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"dist_*/**/*.d.ts"
|
||||||
|
]
|
||||||
|
}
|
||||||
17
tslint.json
17
tslint.json
@@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user