initial commit
This commit is contained in:
2
.npmrc
Normal file
2
.npmrc
Normal file
@@ -0,0 +1,2 @@
|
||||
save-exact=true
|
||||
@techniker-me:registry=https://registry-node.techniker.me
|
||||
2080
package-lock.json
generated
Normal file
2080
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
25
package.json
Normal file
25
package.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "@techniker-me/chatrooms",
|
||||
"version": "0.0.0",
|
||||
"description": "A collections of chatting rooms",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.techniker.me/techniker-me/chatrooms.git"
|
||||
},
|
||||
"license": "ISC",
|
||||
"author": "Alexander Zinn",
|
||||
"type": "module",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev:server": "npm run dev --workspace=server"
|
||||
},
|
||||
"workspaces": [
|
||||
"server"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@types/node": "24.3.1",
|
||||
"nodemon": "3.1.10",
|
||||
"ts-node": "10.9.2",
|
||||
"typescript": "5.9.2"
|
||||
}
|
||||
}
|
||||
9
server/eslint.config.ts
Normal file
9
server/eslint.config.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import js from "@eslint/js";
|
||||
import globals from "globals";
|
||||
import tseslint from "typescript-eslint";
|
||||
import { defineConfig } from "eslint/config";
|
||||
|
||||
export default defineConfig([
|
||||
{ files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: globals.node } },
|
||||
tseslint.configs.recommended,
|
||||
]);
|
||||
26
server/package.json
Normal file
26
server/package.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "server",
|
||||
"version": "0.0.0",
|
||||
"description": "A server for the chatting rooms",
|
||||
"license": "ISC",
|
||||
"author": "Alexander Zinn",
|
||||
"type": "module",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "nodemon --watch 'src/**/*.ts' --exec 'ts-node-esm' src/index.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@techniker-me/logger": "0.0.15"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "9.35.0",
|
||||
"@types/node": "^20.0.0",
|
||||
"eslint": "9.35.0",
|
||||
"globals": "14.0.0",
|
||||
"jiti": "2.5.1",
|
||||
"nodemon": "^3.1.0",
|
||||
"ts-node": "^10.9.0",
|
||||
"typescript": "^5.0.0",
|
||||
"typescript-eslint": "8.42.0"
|
||||
}
|
||||
}
|
||||
29
server/src/Server.ts
Normal file
29
server/src/Server.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import {LoggerFactory} from '@techniker-me/logger';
|
||||
import {createServer as createHttpServer, type IncomingMessage, type ServerResponse, type Server as HTTPServer, type ServerOptions as HTTPServerOptions} from 'node:http';
|
||||
|
||||
export class Server {
|
||||
private readonly _logger = LoggerFactory.getLogger('Server');
|
||||
private readonly _http: HTTPServer;
|
||||
|
||||
constructor(serverOptions: HTTPServerOptions) {
|
||||
this._http = createHttpServer(serverOptions, this.httpRequestHandler.bind(this));
|
||||
}
|
||||
|
||||
public async listen(port: number, callback?: (port: number) => void) {
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
this._http.listen(port, () => {
|
||||
resolve();
|
||||
});
|
||||
this._http.on('error', (error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
|
||||
callback?.(port);
|
||||
}
|
||||
|
||||
private httpRequestHandler(req: IncomingMessage, res: ServerResponse) {
|
||||
this._logger.info(`Received request: ${req.url}`);
|
||||
res.end('Hello World');
|
||||
}
|
||||
}
|
||||
12
server/src/ServerFactory.ts
Normal file
12
server/src/ServerFactory.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import {Server} from './Server.ts';
|
||||
import { type ServerOptions as HTTPServerOptions } from 'node:http';
|
||||
|
||||
export class ServerFactory {
|
||||
public static createServer(serverOptions: HTTPServerOptions): Server {
|
||||
return new Server(serverOptions);
|
||||
}
|
||||
|
||||
private constructor() {
|
||||
throw new Error('ServerFactory is a static class and cannot be instantiated');
|
||||
}
|
||||
}
|
||||
10
server/src/index.ts
Normal file
10
server/src/index.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import {ServerFactory} from './ServerFactory.ts';
|
||||
|
||||
const server = ServerFactory.createServer({
|
||||
keepAlive: true,
|
||||
keepAliveTimeout: 10000,
|
||||
});
|
||||
|
||||
server.listen(3000, (port: number) => {
|
||||
console.log(`Server is running on port [${port}]`);
|
||||
});
|
||||
17
server/tsconfig.json
Normal file
17
server/tsconfig.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "nodenext",
|
||||
"moduleResolution": "nodenext",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true,
|
||||
"allowImportingTsExtensions": true,
|
||||
"noEmit": true
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "dist"],
|
||||
"ts-node": {
|
||||
"esm": true,
|
||||
"experimentalSpecifierResolution": "node"
|
||||
}
|
||||
}
|
||||
45
tsconfig.json
Normal file
45
tsconfig.json
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
// Visit https://aka.ms/tsconfig to read more about this file
|
||||
"compilerOptions": {
|
||||
// File Layout
|
||||
// "rootDir": "./src",
|
||||
// "outDir": "./dist",
|
||||
|
||||
// Environment Settings
|
||||
// See also https://aka.ms/tsconfig/module
|
||||
"module": "nodenext",
|
||||
"target": "esnext",
|
||||
// For nodejs:
|
||||
"lib": ["esnext"],
|
||||
"types": ["node"],
|
||||
|
||||
"outDir": "./dist",
|
||||
|
||||
// Other Outputs
|
||||
"sourceMap": true,
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
|
||||
// Stricter Typechecking Options
|
||||
"noUncheckedIndexedAccess": true,
|
||||
"exactOptionalPropertyTypes": true,
|
||||
|
||||
// Style Options
|
||||
// "noImplicitReturns": true,
|
||||
// "noImplicitOverride": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noPropertyAccessFromIndexSignature": true,
|
||||
|
||||
// Recommended Options
|
||||
"strict": true,
|
||||
"jsx": "react-jsx",
|
||||
"verbatimModuleSyntax": true,
|
||||
"isolatedModules": true,
|
||||
"noUncheckedSideEffectImports": true,
|
||||
"moduleDetection": "force",
|
||||
"skipLibCheck": true,
|
||||
},
|
||||
"include": ["server/src"],
|
||||
}
|
||||
Reference in New Issue
Block a user