update
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user