Compare commits

...

36 Commits

Author SHA1 Message Date
9aebd59c08 2.0.56 2023-07-01 11:55:35 +02:00
be7f4c503e fix(core): update 2023-07-01 11:55:35 +02:00
e1e1d4bf65 2.0.55 2023-07-01 11:49:40 +02:00
20ecb86a9e fix(core): update 2023-07-01 11:49:39 +02:00
83890d7cab 2.0.54 2023-06-12 01:06:22 +02:00
4c87ea8273 fix(core): update 2023-06-12 01:06:21 +02:00
4be625a0d9 2.0.53 2023-04-10 00:55:17 +02:00
c305ca517a fix(core): update 2023-04-10 00:55:16 +02:00
23dccae01b 2.0.52 2023-04-09 23:04:36 +02:00
d5f8d215a2 fix(core): update 2023-04-09 23:04:35 +02:00
3d4f8d1bbe 2.0.51 2023-04-04 17:23:50 +02:00
4724629efa fix(core): update 2023-04-04 17:23:49 +02:00
ff9aea12c3 2.0.50 2023-04-04 17:14:54 +02:00
910b9a495e fix(core): update 2023-04-04 17:14:54 +02:00
7fdf0a71a7 2.0.49 2023-04-01 15:12:55 +02:00
bf2c6660f2 fix(core): update 2023-04-01 15:12:54 +02:00
49afc16422 2.0.48 2023-03-31 18:04:22 +02:00
bb6f239075 fix(core): update 2023-03-31 18:04:21 +02:00
5bd5916696 2.0.47 2023-03-31 15:27:00 +02:00
62df38d083 fix(core): update 2023-03-31 15:26:59 +02:00
d7fe947107 2.0.46 2023-03-31 15:10:43 +02:00
dd426a4ca4 fix(core): update 2023-03-31 15:10:42 +02:00
2a2d4dabe4 2.0.45 2023-03-31 13:18:23 +02:00
830682d382 fix(core): update 2023-03-31 13:18:23 +02:00
d160a92bee 2.0.44 2023-03-30 19:44:44 +02:00
cc421c3321 fix(core): update 2023-03-30 19:44:44 +02:00
92ecef30d3 2.0.43 2023-03-30 19:42:55 +02:00
de4aab6df0 fix(core): update 2023-03-30 19:42:55 +02:00
5624e9dc1f 2.0.42 2023-03-30 19:40:41 +02:00
c7e40e4cde fix(core): update 2023-03-30 19:40:41 +02:00
0704febfc0 2.0.41 2023-03-30 17:44:10 +02:00
b8b1a61ae5 fix(core): update 2023-03-30 17:44:10 +02:00
45155bbce0 2.0.40 2023-03-30 16:44:46 +02:00
35bcf717cb fix(core): update 2023-03-30 16:44:45 +02:00
4d3be1064d 2.0.39 2023-03-30 16:42:02 +02:00
8ee72f9380 fix(core): update 2023-03-30 16:42:02 +02:00
10 changed files with 627 additions and 557 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@apiglobal/typedserver",
"version": "2.0.38",
"version": "2.0.56",
"description": "easy serving of static files",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
@ -39,39 +39,39 @@
"dependencies": {
"@apiglobal/typedrequest": "^2.0.12",
"@apiglobal/typedrequest-interfaces": "^2.0.1",
"@apiglobal/typedsocket": "^2.0.23",
"@apiglobal/typedsocket": "^2.0.24",
"@pushrocks/lik": "^6.0.2",
"@pushrocks/smartchok": "^1.0.23",
"@pushrocks/smartdelay": "^2.0.13",
"@pushrocks/smartdelay": "^3.0.1",
"@pushrocks/smartenv": "^5.0.5",
"@pushrocks/smartfeed": "^1.0.11",
"@pushrocks/smartfile": "^10.0.7",
"@pushrocks/smartlog": "^3.0.1",
"@pushrocks/smartlog-destination-devtools": "^1.0.10",
"@pushrocks/smartmanifest": "^1.0.8",
"@pushrocks/smartmanifest": "^2.0.2",
"@pushrocks/smartmime": "^1.0.5",
"@pushrocks/smartopen": "^2.0.0",
"@pushrocks/smartpath": "^5.0.5",
"@pushrocks/smartpromise": "^3.1.7",
"@pushrocks/smartrequest": "^2.0.11",
"@pushrocks/smartrx": "^3.0.0",
"@pushrocks/smartpromise": "^4.0.2",
"@pushrocks/smartrequest": "^2.0.15",
"@pushrocks/smartrx": "^3.0.2",
"@pushrocks/smartsitemap": "^2.0.1",
"@pushrocks/smarttime": "^4.0.1",
"@pushrocks/webstore": "^2.0.5",
"@tsclass/tsclass": "^4.0.34",
"@pushrocks/webstore": "^2.0.8",
"@tsclass/tsclass": "^4.0.42",
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"express": "^4.18.2",
"express-force-ssl": "^0.3.2",
"lit": "^2.7.0"
"lit": "^2.7.5"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.63",
"@gitzone/tsbundle": "^2.0.6",
"@gitzone/tsrun": "^1.2.39",
"@gitzone/tsbuild": "^2.1.66",
"@gitzone/tsbundle": "^2.0.8",
"@gitzone/tsrun": "^1.2.42",
"@gitzone/tstest": "^1.0.72",
"@pushrocks/tapbundle": "^5.0.4",
"@types/node": "^18.15.11"
"@types/node": "^20.3.0"
},
"private": false,
"browserslist": [

945
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -82,12 +82,11 @@ tap.test('should add typedrequest and typedsocket', async () => {
tap.test('should start the server allright', async () => {
await testServer.start(3000);
console.log('Yay Test Start successfull!');
});
// see if a demo request holds up
tap.test('should issue a request', async (tools) => {
const response = await smartrequest.postJson('http://localhost:3000/someroute', {
const response = await smartrequest.postJson('http://127.0.0.1:3000/someroute', {
headers: {
'X-Forwarded-Proto': 'https',
},
@ -99,20 +98,20 @@ tap.test('should issue a request', async (tools) => {
});
tap.test('should get a file from disk', async () => {
const response = await fetch('http://localhost:3000/someroute/testresponse.js');
const response = await fetch('http://127.0.0.1:3000/someroute/testresponse.js');
console.log(response.status);
console.log(response.headers);
});
tap.test('should answer a preflight request', async () => {
const response = await fetch('http://localhost:3000/some/randompath/', {
const response = await fetch('http://127.0.0.1:3000/some/randompath/', {
method: 'OPTIONS',
});
console.log(response.headers);
});
tap.test('should exposer a sitemap', async () => {
const response = await fetch('http://localhost:3000/sitemap');
const response = await fetch('http://127.0.0.1:3000/sitemap');
console.log(await response.text());
});

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@apiglobal/typedserver',
version: '2.0.38',
version: '2.0.56',
description: 'easy serving of static files'
}

View File

@ -10,3 +10,14 @@ export interface IReq_PushLatestServerChangeTime extends typedrequestInterfaces.
};
response: {}
}
export interface IReq_GetLatestServerChangeTime extends typedrequestInterfaces.implementsTR<
typedrequestInterfaces.ITypedRequest,
IReq_GetLatestServerChangeTime
> {
method: 'getLatestServerChangeTime',
request: {};
response: {
time: number;
}
}

View File

@ -101,16 +101,11 @@ export class Server {
console.log('Using externally supplied http server');
}
this.httpServer.keepAliveTimeout = 600 * 1000;
this.httpServer.headersTimeout = 600 * 1000;
this.httpServer.headersTimeout = 20 * 1000;
// general request handlling
this.expressAppInstance.use((req, res, next) => {
req.on('error', () => {
req.destroy();
});
req.on('timeout', () => {
req.destroy();
});
req.setTimeout(60 * 1000);
next();
});
@ -140,6 +135,9 @@ export class Server {
res.setHeader('Cross-Origin-Resource-Policy', 'cross-origin');
res.setHeader('Cross-Origin-Embedder-Policy', 'unsafe-none');
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('SERVEZONE_ROUTE', 'LOSSLESS_ORIGIN_CONTAINER');
res.setHeader('Cache-Control', 'no-cache');
res.setHeader('Expires', new Date(Date.now()).toUTCString());
next();
});

View File

@ -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';
@ -72,31 +72,20 @@ export class TypedServer {
public ended = false;
constructor(optionsArg: IServerOptions) {
const standardOptions: IServerOptions = {
injectReload: true,
port: 3000,
serveDir: process.cwd(),
watch: true,
injectReload: false,
serveDir: null,
watch: false,
cors: true,
};
this.options = {
...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,81 @@ 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
);
// lets setup typedrouter
this.typedrouter.addTypedHandler<interfaces.IReq_GetLatestServerChangeTime>(new plugins.typedrequest.TypedHandler('getLatestServerChangeTime', async reqDataArg => {
return {
time: this.lastReload,
}
}))
// console.log('open url in browser');
// await plugins.smartopen.openUrl(`http://testing.git.zone:${this.options.port}`);
}
@ -189,7 +192,7 @@ export class TypedServer {
*/
public async reload() {
this.lastReload = Date.now();
for (const connectionArg of await this.typedsocket.findAllTargetConnections(async () => true)) {
for (const connectionArg of await this.typedsocket.findAllTargetConnectionsByTag('typedserver_frontend')) {
const pushTime =
this.typedsocket.createTypedRequest<interfaces.IReq_PushLatestServerChangeTime>(
'pushLatestServerChangeTime',
@ -203,9 +206,11 @@ 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();
if (this.smartchokInstance) {
await this.smartchokInstance.stop();
}
}
public async createServeDirHash() {

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@apiglobal/typedserver',
version: '2.0.38',
version: '2.0.56',
description: 'easy serving of static files'
}

View File

@ -61,11 +61,15 @@ export class ReloadChecker {
public async checkReload(lastServerChange: number) {
let reloadJustified = false;
(await this.store.get(this.storeKey)) !== lastServerChange ? (reloadJustified = true) : null;
let storedLastServerChange = await this.store.get(this.storeKey);
if (storedLastServerChange && storedLastServerChange !== lastServerChange) {
reloadJustified = true;
} else {
}
if (reloadJustified) {
this.store.set(this.storeKey, lastServerChange);
const reloadText = `about to reload ${
const reloadText = `upgrading... ${
globalThis.globalSw ? '(purging the sw cache first...)' : ''
}`;
this.infoscreen.setText(reloadText);
@ -98,18 +102,29 @@ export class ReloadChecker {
this.typedrouter,
plugins.typedsocket.TypedSocket.useWindowLocationOriginUrl()
);
this.typedsocket.eventSubject.subscribe(eventArg => {
this.typedsocket.addTag('typedserver_frontend', {});
this.typedsocket.eventSubject.subscribe(async (eventArg) => {
console.log(`typedsocket event subscription: ${eventArg}`);
if (eventArg === 'disconnected' || eventArg === 'disconnecting' || eventArg === 'timedOut') {
if (
eventArg === 'disconnected' ||
eventArg === 'disconnecting' ||
eventArg === 'timedOut'
) {
this.backendConnectionLost = true;
this.infoscreen.setText(`typedsocket ${eventArg}!`)
this.infoscreen.setText(`typedsocket ${eventArg}!`);
} else if (eventArg === 'connected' && this.backendConnectionLost) {
this.backendConnectionLost = false;
this.infoscreen.setSuccess('typedsocket connected!')
this.infoscreen.setSuccess('typedsocket connected!');
// lets check if a reload is necessary
const getLatestServerChangeTime =
this.typedsocket.createTypedRequest<interfaces.IReq_GetLatestServerChangeTime>(
'getLatestServerChangeTime'
);
const response = await getLatestServerChangeTime.fire({});
this.checkReload(response.time);
}
});
logger.log('success', `ReloadChecker connected through typedsocket!`)
logger.log('success', `ReloadChecker connected through typedsocket!`);
}
}

View File

@ -95,10 +95,13 @@ export class TypedserverInfoscreen extends LitElement {
public async hide() {
this.text = '';
const mainbox = this.shadowRoot.querySelector('.mainbox');
mainbox.classList.add('show');
if (this.appended) {
const mainbox = this.shadowRoot.querySelector('.mainbox');
mainbox.classList.remove('show');
}
await plugins.smartdelay.delayFor(300);
if (this.appended) {
this.appended = false;
document.body.removeChild(this);
}
}