fix(core): update
This commit is contained in:
parent
45155bbce0
commit
b8b1a61ae5
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@apiglobal/typedserver',
|
||||
version: '2.0.40',
|
||||
version: '2.0.41',
|
||||
description: 'easy serving of static files'
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ export class TypedServer {
|
||||
|
||||
// instance
|
||||
public options: IServerOptions;
|
||||
public serverInstance: servertools.Server;
|
||||
public server: servertools.Server;
|
||||
public smartchokInstance: plugins.smartchok.Smartchok;
|
||||
public serveDirHashSubject = new plugins.smartrx.rxjs.ReplaySubject<string>(1);
|
||||
public serveHash: string = '000000';
|
||||
@ -82,21 +82,10 @@ export class TypedServer {
|
||||
...standardOptions,
|
||||
...optionsArg,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* inits and starts the server
|
||||
*/
|
||||
public async start() {
|
||||
// set the smartexpress instance
|
||||
this.serverInstance = new servertools.Server({
|
||||
port: this.options.port,
|
||||
forceSsl: false,
|
||||
cors: true,
|
||||
});
|
||||
|
||||
|
||||
this.server = new servertools.Server(this.options);
|
||||
// add routes to the smartexpress instance
|
||||
this.serverInstance.addRoute(
|
||||
this.server.addRoute(
|
||||
'/typedserver/:request',
|
||||
new servertools.Handler('ALL', async (req, res) => {
|
||||
switch (req.params.request) {
|
||||
@ -120,67 +109,74 @@ export class TypedServer {
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
this.serverInstance.addRoute(
|
||||
'/*',
|
||||
new servertools.HandlerStatic(this.options.serveDir, {
|
||||
responseModifier: async (responseArg) => {
|
||||
let fileString = responseArg.responseContent;
|
||||
if (plugins.path.parse(responseArg.path).ext === '.html') {
|
||||
const fileStringArray = fileString.split('<head>');
|
||||
if (this.options.injectReload && fileStringArray.length === 2) {
|
||||
fileStringArray[0] = `${fileStringArray[0]}<head>
|
||||
<!-- injected by @apiglobal/typedserver start -->
|
||||
<script async defer type="module" src="/typedserver/devtools"></script>
|
||||
<script>
|
||||
globalThis.typedserver = {
|
||||
lastReload: '${this.lastReload}',
|
||||
versionInfo: ${JSON.stringify({}, null, 2)},
|
||||
}
|
||||
</script>
|
||||
<!-- injected by @apiglobal/typedserver stop -->
|
||||
`;
|
||||
fileString = fileStringArray.join('');
|
||||
console.log('injected typedserver script.');
|
||||
} else if (this.options.injectReload) {
|
||||
console.log('Could not insert typedserver script');
|
||||
/**
|
||||
* inits and starts the server
|
||||
*/
|
||||
public async start() {
|
||||
if(this.options.serveDir) {
|
||||
this.server.addRoute(
|
||||
'/*',
|
||||
new servertools.HandlerStatic(this.options.serveDir, {
|
||||
responseModifier: async (responseArg) => {
|
||||
let fileString = responseArg.responseContent;
|
||||
if (plugins.path.parse(responseArg.path).ext === '.html') {
|
||||
const fileStringArray = fileString.split('<head>');
|
||||
if (this.options.injectReload && fileStringArray.length === 2) {
|
||||
fileStringArray[0] = `${fileStringArray[0]}<head>
|
||||
<!-- injected by @apiglobal/typedserver start -->
|
||||
<script async defer type="module" src="/typedserver/devtools"></script>
|
||||
<script>
|
||||
globalThis.typedserver = {
|
||||
lastReload: '${this.lastReload}',
|
||||
versionInfo: ${JSON.stringify({}, null, 2)},
|
||||
}
|
||||
</script>
|
||||
<!-- injected by @apiglobal/typedserver stop -->
|
||||
`;
|
||||
fileString = fileStringArray.join('');
|
||||
console.log('injected typedserver script.');
|
||||
} else if (this.options.injectReload) {
|
||||
console.log('Could not insert typedserver script');
|
||||
}
|
||||
}
|
||||
}
|
||||
const headers = responseArg.headers;
|
||||
headers.appHash = this.serveHash;
|
||||
headers['Cache-Control'] = 'no-cache, no-store, must-revalidate';
|
||||
headers['Pragma'] = 'no-cache';
|
||||
headers['Expires'] = '0';
|
||||
return {
|
||||
headers,
|
||||
path: responseArg.path,
|
||||
responseContent: fileString,
|
||||
};
|
||||
},
|
||||
serveIndexHtmlDefault: true,
|
||||
})
|
||||
);
|
||||
|
||||
this.smartchokInstance = new plugins.smartchok.Smartchok([this.options.serveDir], {});
|
||||
if (this.options.watch) {
|
||||
const headers = responseArg.headers;
|
||||
headers.appHash = this.serveHash;
|
||||
headers['Cache-Control'] = 'no-cache, no-store, must-revalidate';
|
||||
headers['Pragma'] = 'no-cache';
|
||||
headers['Expires'] = '0';
|
||||
return {
|
||||
headers,
|
||||
path: responseArg.path,
|
||||
responseContent: fileString,
|
||||
};
|
||||
},
|
||||
serveIndexHtmlDefault: true,
|
||||
})
|
||||
);
|
||||
} else if (this.options.injectReload) {
|
||||
throw new Error('You set to inject the reload script without a serve dir. This is not supported at the moment.')
|
||||
}
|
||||
if (this.options.watch && this.options.serveDir) {
|
||||
this.smartchokInstance = new plugins.smartchok.Smartchok([this.options.serveDir], {});
|
||||
await this.smartchokInstance.start();
|
||||
(await this.smartchokInstance.getObservableFor('change')).subscribe(async () => {
|
||||
await this.createServeDirHash();
|
||||
this.reload();
|
||||
});
|
||||
await this.createServeDirHash();
|
||||
}
|
||||
|
||||
await this.createServeDirHash();
|
||||
|
||||
// lets start the server
|
||||
await this.serverInstance.start();
|
||||
console.log('open url in browser');
|
||||
await this.server.start();
|
||||
|
||||
this.typedsocket = await plugins.typedsocket.TypedSocket.createServer(
|
||||
this.typedrouter,
|
||||
this.serverInstance
|
||||
this.server
|
||||
);
|
||||
|
||||
// console.log('open url in browser');
|
||||
// await plugins.smartopen.openUrl(`http://testing.git.zone:${this.options.port}`);
|
||||
}
|
||||
|
||||
@ -203,7 +199,7 @@ export class TypedServer {
|
||||
|
||||
public async stop() {
|
||||
this.ended = true;
|
||||
await this.serverInstance.stop();
|
||||
await this.server.stop();
|
||||
await this.typedsocket.stop();
|
||||
await this.smartchokInstance.stop();
|
||||
}
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@apiglobal/typedserver',
|
||||
version: '2.0.40',
|
||||
version: '2.0.41',
|
||||
description: 'easy serving of static files'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user