update
This commit is contained in:
@@ -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({
|
||||
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 plugins from './plugins';
|
||||
import * as paths from './paths';
|
||||
import * as ntml from './ntml';
|
||||
import * as interfaces from './interfaces.js';
|
||||
import * as plugins from './plugins.js';
|
||||
import * as paths from './paths.js';
|
||||
import * as ntml from './ntml/index.js';
|
||||
|
||||
export interface IPublicServerOptions {
|
||||
packageBaseDirectory?: string;
|
||||
@@ -17,9 +17,7 @@ export interface IPublicServerOptions {
|
||||
*/
|
||||
export class UiPublicServer {
|
||||
public projectinfo = new plugins.projectinfo.ProjectinfoNpm(paths.packageDir);
|
||||
public readme = new plugins.smartmarkdown.SmartMarkdown().markdownToHtml(
|
||||
plugins.smartfile.fs.toStringSync(plugins.path.join(paths.packageDir, 'readme.md'))
|
||||
);
|
||||
public readme: string;
|
||||
public startedAt: string;
|
||||
private server: plugins.http.Server;
|
||||
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
|
||||
*/
|
||||
public async startServer() {
|
||||
console.log('starting the uipublicserver');
|
||||
|
||||
// Initialize readme
|
||||
await this.initReadme();
|
||||
|
||||
const done = plugins.smartpromise.defer();
|
||||
const expressApplication = plugins.express();
|
||||
|
||||
@@ -235,7 +246,7 @@ export class UiPublicServer {
|
||||
|
||||
const requestDescriptor = `${packageName}/${filePath}/${distTag}/${version}`;
|
||||
|
||||
let smartfile: plugins.smartfile.Smartfile;
|
||||
let smartfile: plugins.smartfile.SmartFile;
|
||||
|
||||
// protect against parallel requests
|
||||
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 {
|
||||
headers: {
|
||||
'cache-control': `max-age=${
|
||||
@@ -276,7 +291,7 @@ export class UiPublicServer {
|
||||
: plugins.smarttime.getMilliSecondsFromUnits({ days: 1 })) / 1000
|
||||
}`,
|
||||
'content-length': smartfile.contentBuffer.length.toString(),
|
||||
'content-type': plugins.smartmime.detectMimeType(smartfile.path),
|
||||
'content-type': contentType,
|
||||
},
|
||||
status: 200,
|
||||
body: smartfile.contentBuffer,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { UiPublicServer } from '../npm-publicserver.classes.uipublicserver';
|
||||
import * as plugins from '../plugins';
|
||||
import type { UiPublicServer } from '../npm-publicserver.classes.uipublicserver.js';
|
||||
import * as plugins from '../plugins.js';
|
||||
|
||||
export const getBody = async (uipublicServerArg: UiPublicServer, contentArg: string | string[]) => {
|
||||
return await plugins.litNtml.html`
|
||||
<head></head>
|
||||
@@ -50,7 +51,7 @@ export const getBody = async (uipublicServerArg: UiPublicServer, contentArg: str
|
||||
</div>
|
||||
${contentArg}
|
||||
<div class="footer">
|
||||
UiPublicServer v${uipublicServerArg.projectinfo.version} |
|
||||
UiPublicServer v${uipublicServerArg.projectinfo.version} |
|
||||
running since ${uipublicServerArg.startedAt} |
|
||||
<a href="https://lossless.gmbh" target="_blank">Legal Info</a></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 };
|
||||
|
||||
// @pushrocks scope (maintained by Lossless GmbH)
|
||||
import * as projectinfo from '@pushrocks/projectinfo';
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import * as smartmime from '@pushrocks/smartmime';
|
||||
import * as smartmarkdown from '@pushrocks/smartmarkdown';
|
||||
import * as smartnpm from '@pushrocks/smartnpm';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smarttime from '@pushrocks/smarttime';
|
||||
// @push.rocks scope
|
||||
import * as projectinfo from '@push.rocks/projectinfo';
|
||||
import * as smartdelay from '@push.rocks/smartdelay';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smartmime from '@push.rocks/smartmime';
|
||||
import * as smartmarkdown from '@push.rocks/smartmarkdown';
|
||||
import * as smartnpm from '@push.rocks/smartnpm';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as smarttime from '@push.rocks/smarttime';
|
||||
|
||||
export {
|
||||
projectinfo,
|
||||
@@ -31,6 +31,5 @@ import compression from 'compression';
|
||||
import express from 'express';
|
||||
import * as litNtml from 'lit-ntml';
|
||||
import * as promClient from 'prom-client';
|
||||
import splunkLogging from 'splunk-logging';
|
||||
|
||||
export { compression, express, litNtml, promClient, splunkLogging };
|
||||
export { compression, express, litNtml, promClient };
|
||||
|
||||
Reference in New Issue
Block a user