├── .editorconfig
├── .eslintrc.json
├── .gitignore
├── .prettierignore
├── .prettierrc
├── .vscode
└── extensions.json
├── README.md
├── apps
└── sandbox
│ ├── .browserslistrc
│ ├── .eslintrc.json
│ ├── jest.config.ts
│ ├── project.json
│ ├── src
│ ├── app
│ │ ├── app.component.html
│ │ ├── app.component.spec.ts
│ │ ├── app.component.ts
│ │ └── app.module.ts
│ ├── assets
│ │ └── .gitkeep
│ ├── environments
│ │ ├── environment.prod.ts
│ │ └── environment.ts
│ ├── main.ts
│ ├── polyfills.ts
│ └── test-setup.ts
│ ├── tsconfig.app.json
│ ├── tsconfig.editor.json
│ ├── tsconfig.json
│ └── tsconfig.spec.json
├── jest.config.ts
├── jest.preset.js
├── libs
├── platform
│ ├── .eslintrc.json
│ ├── README.md
│ ├── jest.config.ts
│ ├── ng-package.json
│ ├── package.json
│ ├── project.json
│ ├── src
│ │ ├── index.ts
│ │ ├── lib
│ │ │ ├── error-handler.ts
│ │ │ ├── loader.ts
│ │ │ ├── platform.module.ts
│ │ │ ├── platform.ts
│ │ │ ├── renderer.ts
│ │ │ ├── sanitizer.ts
│ │ │ └── schema-registry.ts
│ │ └── test-setup.ts
│ ├── tsconfig.json
│ ├── tsconfig.lib.json
│ ├── tsconfig.lib.prod.json
│ └── tsconfig.spec.json
└── server
│ ├── .eslintrc.json
│ ├── README.md
│ ├── jest.config.ts
│ ├── ng-package.json
│ ├── package.json
│ ├── project.json
│ ├── src
│ ├── index.ts
│ ├── lib
│ │ ├── controller.ts
│ │ ├── controllers
│ │ │ ├── content-type-html.directive.spec.ts
│ │ │ └── content-type-html.directive.ts
│ │ ├── get
│ │ │ ├── get.component.spec.ts
│ │ │ └── get.component.ts
│ │ ├── server.module.ts
│ │ └── server
│ │ │ ├── server.component.html
│ │ │ ├── server.component.spec.ts
│ │ │ └── server.component.ts
│ └── test-setup.ts
│ ├── tsconfig.json
│ ├── tsconfig.lib.json
│ ├── tsconfig.lib.prod.json
│ └── tsconfig.spec.json
├── nx.json
├── package-lock.json
├── package.json
├── tools
├── generators
│ └── .gitkeep
└── tsconfig.tools.json
├── tsconfig.base.json
└── workspace.json
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | max_line_length = off
13 | trim_trailing_whitespace = false
14 |
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "root": true,
3 | "ignorePatterns": ["**/*"],
4 | "plugins": ["@nrwl/nx"],
5 | "overrides": [
6 | {
7 | "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
8 | "rules": {
9 | "@nrwl/nx/enforce-module-boundaries": [
10 | "error",
11 | {
12 | "enforceBuildableLibDependency": true,
13 | "allow": [],
14 | "depConstraints": [
15 | {
16 | "sourceTag": "*",
17 | "onlyDependOnLibsWithTags": ["*"]
18 | }
19 | ]
20 | }
21 | ]
22 | }
23 | },
24 | {
25 | "files": ["*.ts", "*.tsx"],
26 | "extends": ["plugin:@nrwl/nx/typescript"],
27 | "rules": {}
28 | },
29 | {
30 | "files": ["*.js", "*.jsx"],
31 | "extends": ["plugin:@nrwl/nx/javascript"],
32 | "rules": {}
33 | },
34 | {
35 | "files": ["*.spec.ts", "*.spec.tsx", "*.spec.js", "*.spec.jsx"],
36 | "env": {
37 | "jest": true
38 | },
39 | "rules": {}
40 | }
41 | ]
42 | }
43 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist
5 | /tmp
6 | /out-tsc
7 |
8 | # dependencies
9 | node_modules
10 |
11 | # IDEs and editors
12 | /.idea
13 | .project
14 | .classpath
15 | .c9/
16 | *.launch
17 | .settings/
18 | *.sublime-workspace
19 |
20 | # IDE - VSCode
21 | .vscode/*
22 | !.vscode/settings.json
23 | !.vscode/tasks.json
24 | !.vscode/launch.json
25 | !.vscode/extensions.json
26 |
27 | # misc
28 | /.sass-cache
29 | /connect.lock
30 | /coverage
31 | /libpeerconnection.log
32 | npm-debug.log
33 | yarn-error.log
34 | testem.log
35 | /typings
36 |
37 | # System Files
38 | .DS_Store
39 | Thumbs.db
40 |
41 | .angular
42 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | # Add files here to ignore them from prettier formatting
2 |
3 | /dist
4 | /coverage
5 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true
3 | }
4 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": [
3 | "nrwl.angular-console",
4 | "esbenp.prettier-vscode",
5 | "firsttris.vscode-jest-runner",
6 | "dbaeumer.vscode-eslint"
7 | ]
8 | }
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # NgHttp
4 |
5 | This project was generated using [Nx](https://nx.dev).
6 |
7 |

8 |
9 | 🔎 **Smart, Fast and Extensible Build System**
10 |
11 | ## Adding capabilities to your workspace
12 |
13 | Nx supports many plugins which add capabilities for developing different types of applications and different tools.
14 |
15 | These capabilities include generating applications, libraries, etc as well as the devtools to test, and build projects as well.
16 |
17 | Below are our core plugins:
18 |
19 | - [React](https://reactjs.org)
20 | - `npm install --save-dev @nrwl/react`
21 | - Web (no framework frontends)
22 | - `npm install --save-dev @nrwl/web`
23 | - [Angular](https://angular.io)
24 | - `npm install --save-dev @nrwl/angular`
25 | - [Nest](https://nestjs.com)
26 | - `npm install --save-dev @nrwl/nest`
27 | - [Express](https://expressjs.com)
28 | - `npm install --save-dev @nrwl/express`
29 | - [Node](https://nodejs.org)
30 | - `npm install --save-dev @nrwl/node`
31 |
32 | There are also many [community plugins](https://nx.dev/community) you could add.
33 |
34 | ## Generate an application
35 |
36 | Run `nx g @nrwl/react:app my-app` to generate an application.
37 |
38 | > You can use any of the plugins above to generate applications as well.
39 |
40 | When using Nx, you can create multiple applications and libraries in the same workspace.
41 |
42 | ## Generate a library
43 |
44 | Run `nx g @nrwl/react:lib my-lib` to generate a library.
45 |
46 | > You can also use any of the plugins above to generate libraries as well.
47 |
48 | Libraries are shareable across libraries and applications. They can be imported from `@ng-http/mylib`.
49 |
50 | ## Development server
51 |
52 | Run `nx serve my-app` for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.
53 |
54 | ## Code scaffolding
55 |
56 | Run `nx g @nrwl/react:component my-component --project=my-app` to generate a new component.
57 |
58 | ## Build
59 |
60 | Run `nx build my-app` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.
61 |
62 | ## Running unit tests
63 |
64 | Run `nx test my-app` to execute the unit tests via [Jest](https://jestjs.io).
65 |
66 | Run `nx affected:test` to execute the unit tests affected by a change.
67 |
68 | ## Running end-to-end tests
69 |
70 | Run `nx e2e my-app` to execute the end-to-end tests via [Cypress](https://www.cypress.io).
71 |
72 | Run `nx affected:e2e` to execute the end-to-end tests affected by a change.
73 |
74 | ## Understand your workspace
75 |
76 | Run `nx graph` to see a diagram of the dependencies of your projects.
77 |
78 | ## Further help
79 |
80 | Visit the [Nx Documentation](https://nx.dev) to learn more.
81 |
82 |
83 |
84 | ## ☁ Nx Cloud
85 |
86 | ### Distributed Computation Caching & Distributed Task Execution
87 |
88 | 
89 |
90 | Nx Cloud pairs with Nx in order to enable you to build and test code more rapidly, by up to 10 times. Even teams that are new to Nx can connect to Nx Cloud and start saving time instantly.
91 |
92 | Teams using Nx gain the advantage of building full-stack applications with their preferred framework alongside Nx’s advanced code generation and project dependency graph, plus a unified experience for both frontend and backend developers.
93 |
94 | Visit [Nx Cloud](https://nx.app/) to learn more.
95 |
--------------------------------------------------------------------------------
/apps/sandbox/.browserslistrc:
--------------------------------------------------------------------------------
1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
2 | # For additional information regarding the format and rule options, please see:
3 | # https://github.com/browserslist/browserslist#queries
4 |
5 | # For the full list of supported browsers by the Angular framework, please see:
6 | # https://angular.io/guide/browser-support
7 |
8 | # You can see what browsers were selected by your queries by running:
9 | # npx browserslist
10 |
11 | last 1 Chrome version
12 | last 1 Firefox version
13 | last 2 Edge major versions
14 | last 2 Safari major versions
15 | last 2 iOS major versions
16 | Firefox ESR
17 |
--------------------------------------------------------------------------------
/apps/sandbox/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": ["../../.eslintrc.json"],
3 | "ignorePatterns": ["!**/*"],
4 | "overrides": [
5 | {
6 | "files": ["*.ts"],
7 | "extends": [
8 | "plugin:@nrwl/nx/angular",
9 | "plugin:@angular-eslint/template/process-inline-templates"
10 | ],
11 | "rules": {
12 | "@angular-eslint/directive-selector": [
13 | "error",
14 | {
15 | "type": "attribute",
16 | "prefix": "ngHttp",
17 | "style": "camelCase"
18 | }
19 | ],
20 | "@angular-eslint/component-selector": [
21 | "error",
22 | {
23 | "type": "element",
24 | "prefix": "ng-http",
25 | "style": "kebab-case"
26 | }
27 | ]
28 | }
29 | },
30 | {
31 | "files": ["*.html"],
32 | "extends": ["plugin:@nrwl/nx/angular-template"],
33 | "rules": {}
34 | }
35 | ]
36 | }
37 |
--------------------------------------------------------------------------------
/apps/sandbox/jest.config.ts:
--------------------------------------------------------------------------------
1 | /* eslint-disable */
2 | export default {
3 | displayName: 'sandbox',
4 | preset: '../../jest.preset.js',
5 | setupFilesAfterEnv: ['/src/test-setup.ts'],
6 | globals: {
7 | 'ts-jest': {
8 | tsconfig: '/tsconfig.spec.json',
9 | stringifyContentPathRegex: '\\.(html|svg)$',
10 | },
11 | },
12 | coverageDirectory: '../../coverage/apps/sandbox',
13 | transform: {
14 | '^.+\\.(ts|mjs|js|html)$': 'jest-preset-angular',
15 | },
16 | transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
17 | snapshotSerializers: [
18 | 'jest-preset-angular/build/serializers/no-ng-attributes',
19 | 'jest-preset-angular/build/serializers/ng-snapshot',
20 | 'jest-preset-angular/build/serializers/html-comment',
21 | ],
22 | };
23 |
--------------------------------------------------------------------------------
/apps/sandbox/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "projectType": "application",
3 | "sourceRoot": "apps/sandbox/src",
4 | "prefix": "ng-http",
5 | "targets": {
6 | "build": {
7 | "executor": "@angular-devkit/build-angular:server",
8 | "outputs": ["{options.outputPath}"],
9 | "options": {
10 | "outputPath": "dist/apps/sandbox",
11 | "main": "apps/sandbox/src/main.ts",
12 | "tsConfig": "apps/sandbox/tsconfig.app.json",
13 | "bundleDependencies": true
14 | },
15 | "configurations": {
16 | "production": {
17 | "outputHashing": "media",
18 | "fileReplacements": [
19 | {
20 | "replace": "apps/sandbox/src/environments/environment.ts",
21 | "with": "apps/sandbox/src/environments/environment.prod.ts"
22 | }
23 | ],
24 | "sourceMap": false,
25 | "optimization": true
26 | }
27 | },
28 | "defaultConfiguration": ""
29 | },
30 | "lint": {
31 | "executor": "@nrwl/linter:eslint",
32 | "options": {
33 | "lintFilePatterns": ["apps/sandbox/**/*.ts", "apps/sandbox/**/*.html"]
34 | }
35 | },
36 | "test": {
37 | "executor": "@nrwl/jest:jest",
38 | "outputs": ["coverage/apps/sandbox"],
39 | "options": {
40 | "jestConfig": "apps/sandbox/jest.config.ts",
41 | "passWithNoTests": true
42 | }
43 | }
44 | },
45 | "tags": []
46 | }
47 |
--------------------------------------------------------------------------------
/apps/sandbox/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Some content
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/apps/sandbox/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed } from '@angular/core/testing';
2 | import { AppComponent } from './app.component';
3 |
4 | describe('AppComponent', () => {
5 | beforeEach(async () => {
6 | await TestBed.configureTestingModule({
7 | declarations: [AppComponent],
8 | }).compileComponents();
9 | });
10 |
11 | it('should create the app', () => {
12 | const fixture = TestBed.createComponent(AppComponent);
13 | const app = fixture.componentInstance;
14 | expect(app).toBeTruthy();
15 | });
16 |
17 | it(`should have as title 'sandbox'`, () => {
18 | const fixture = TestBed.createComponent(AppComponent);
19 | const app = fixture.componentInstance;
20 | expect(app.title).toEqual('sandbox');
21 | });
22 |
23 | it('should render title', () => {
24 | const fixture = TestBed.createComponent(AppComponent);
25 | fixture.detectChanges();
26 | const compiled = fixture.nativeElement;
27 | expect(compiled.querySelector('h1').textContent).toContain(
28 | 'Welcome to sandbox!'
29 | );
30 | });
31 | });
32 |
--------------------------------------------------------------------------------
/apps/sandbox/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'ng-http-root',
5 | templateUrl: './app.component.html',
6 | })
7 | export class AppComponent {}
8 |
--------------------------------------------------------------------------------
/apps/sandbox/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
2 |
3 | import { AppComponent } from './app.component';
4 | import { PlatformModule } from '@ng-http/platform';
5 | import { CommonModule } from '@angular/common';
6 | import { ServerModule } from '@ng-http/server';
7 |
8 | @NgModule({
9 | declarations: [AppComponent],
10 | imports: [PlatformModule, CommonModule, ServerModule],
11 | providers: [],
12 | bootstrap: [AppComponent],
13 | })
14 | export class AppModule {}
15 |
--------------------------------------------------------------------------------
/apps/sandbox/src/assets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IKatsuba/ng-http/68416c71013291202b2c9261c78668365aaab0f5/apps/sandbox/src/assets/.gitkeep
--------------------------------------------------------------------------------
/apps/sandbox/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true,
3 | };
4 |
--------------------------------------------------------------------------------
/apps/sandbox/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // This file can be replaced during build by using the `fileReplacements` array.
2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
3 | // The list of file replacements can be found in `angular.json`.
4 |
5 | export const environment = {
6 | production: false,
7 | };
8 |
9 | /*
10 | * For easier debugging in development mode, you can import the following file
11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
12 | *
13 | * This import should be commented out in production mode because it will have a negative impact
14 | * on performance if an error is thrown.
15 | */
16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI.
17 |
--------------------------------------------------------------------------------
/apps/sandbox/src/main.ts:
--------------------------------------------------------------------------------
1 | import { enableProdMode } from '@angular/core';
2 |
3 | import { AppModule } from './app/app.module';
4 | import { platformHttpDynamic } from '@ng-http/platform';
5 |
6 | enableProdMode();
7 |
8 | platformHttpDynamic()
9 | .bootstrapModule(AppModule)
10 | .catch((err) => console.error(err));
11 |
--------------------------------------------------------------------------------
/apps/sandbox/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/guide/browser-support
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE11 requires the following for NgClass support on SVG elements */
22 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
23 |
24 | /**
25 | * Web Animations `@angular/platform-browser/animations`
26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
28 | */
29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
30 |
31 | /**
32 | * By default, zone.js will patch all possible macroTask and DomEvents
33 | * user can disable parts of macroTask/DomEvents patch by setting following flags
34 | * because those flags need to be set before `zone.js` being loaded, and webpack
35 | * will put import in the top of bundle, so user need to create a separate file
36 | * in this directory (for example: zone-flags.ts), and put the following flags
37 | * into that file, and then add the following code before importing zone.js.
38 | * import './zone-flags';
39 | *
40 | * The flags allowed in zone-flags.ts are listed here.
41 | *
42 | * The following flags will work for all browsers.
43 | *
44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
47 | *
48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge
50 | *
51 | * (window as any).__Zone_enable_cross_context_check = true;
52 | *
53 | */
54 |
55 | /***************************************************************************************************
56 | * Zone JS is required by default for Angular itself.
57 | */
58 | import 'zone.js/dist/zone'; // Included with Angular CLI.
59 |
60 | /***************************************************************************************************
61 | * APPLICATION IMPORTS
62 | */
63 |
--------------------------------------------------------------------------------
/apps/sandbox/src/test-setup.ts:
--------------------------------------------------------------------------------
1 | import 'jest-preset-angular/setup-jest';
2 |
--------------------------------------------------------------------------------
/apps/sandbox/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../../dist/out-tsc",
5 | "types": []
6 | },
7 | "files": ["src/main.ts", "src/polyfills.ts"],
8 | "include": ["src/**/*.d.ts"],
9 | "exclude": ["jest.config.ts", "**/*.test.ts", "**/*.spec.ts"]
10 | }
11 |
--------------------------------------------------------------------------------
/apps/sandbox/tsconfig.editor.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "include": ["**/*.ts"],
4 | "compilerOptions": {
5 | "types": ["jest", "node"]
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/apps/sandbox/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig.base.json",
3 | "files": [],
4 | "include": [],
5 | "references": [
6 | {
7 | "path": "./tsconfig.app.json"
8 | },
9 | {
10 | "path": "./tsconfig.spec.json"
11 | },
12 | {
13 | "path": "./tsconfig.editor.json"
14 | }
15 | ],
16 | "compilerOptions": {
17 | "target": "es2020",
18 | "forceConsistentCasingInFileNames": true,
19 | "strict": true,
20 | "noImplicitOverride": true,
21 | "noPropertyAccessFromIndexSignature": true,
22 | "noImplicitReturns": true,
23 | "noFallthroughCasesInSwitch": true
24 | },
25 | "angularCompilerOptions": {
26 | "enableI18nLegacyMessageIdFormat": false,
27 | "strictInjectionParameters": true,
28 | "strictInputAccessModifiers": true,
29 | "strictTemplates": true
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/apps/sandbox/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../../dist/out-tsc",
5 | "module": "commonjs",
6 | "types": ["jest", "node"]
7 | },
8 | "files": ["src/test-setup.ts"],
9 | "include": ["jest.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
10 | }
11 |
--------------------------------------------------------------------------------
/jest.config.ts:
--------------------------------------------------------------------------------
1 | import { getJestProjects } from '@nrwl/jest';
2 |
3 | export default {
4 | projects: getJestProjects(),
5 | };
6 |
--------------------------------------------------------------------------------
/jest.preset.js:
--------------------------------------------------------------------------------
1 | const nxPreset = require('@nrwl/jest/preset').default;
2 |
3 | module.exports = { ...nxPreset };
4 |
--------------------------------------------------------------------------------
/libs/platform/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": ["../../.eslintrc.json"],
3 | "ignorePatterns": ["!**/*"],
4 | "overrides": [
5 | {
6 | "files": ["*.ts"],
7 | "extends": [
8 | "plugin:@nrwl/nx/angular",
9 | "plugin:@angular-eslint/template/process-inline-templates"
10 | ],
11 | "rules": {
12 | "@angular-eslint/directive-selector": [
13 | "error",
14 | {
15 | "type": "attribute",
16 | "prefix": "ngHttp",
17 | "style": "camelCase"
18 | }
19 | ],
20 | "@angular-eslint/component-selector": [
21 | "error",
22 | {
23 | "type": "element",
24 | "prefix": "ng-http",
25 | "style": "kebab-case"
26 | }
27 | ]
28 | }
29 | },
30 | {
31 | "files": ["*.html"],
32 | "extends": ["plugin:@nrwl/nx/angular-template"],
33 | "rules": {}
34 | }
35 | ]
36 | }
37 |
--------------------------------------------------------------------------------
/libs/platform/README.md:
--------------------------------------------------------------------------------
1 | # platform
2 |
3 | This library was generated with [Nx](https://nx.dev).
4 |
5 | ## Running unit tests
6 |
7 | Run `nx test platform` to execute the unit tests.
8 |
--------------------------------------------------------------------------------
/libs/platform/jest.config.ts:
--------------------------------------------------------------------------------
1 | /* eslint-disable */
2 | export default {
3 | displayName: 'platform',
4 | preset: '../../jest.preset.js',
5 | setupFilesAfterEnv: ['/src/test-setup.ts'],
6 | globals: {
7 | 'ts-jest': {
8 | tsconfig: '/tsconfig.spec.json',
9 | stringifyContentPathRegex: '\\.(html|svg)$',
10 | },
11 | },
12 | coverageDirectory: '../../coverage/libs/platform',
13 | transform: {
14 | '^.+\\.(ts|mjs|js|html)$': 'jest-preset-angular',
15 | },
16 | transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
17 | snapshotSerializers: [
18 | 'jest-preset-angular/build/serializers/no-ng-attributes',
19 | 'jest-preset-angular/build/serializers/ng-snapshot',
20 | 'jest-preset-angular/build/serializers/html-comment',
21 | ],
22 | };
23 |
--------------------------------------------------------------------------------
/libs/platform/ng-package.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3 | "dest": "../../dist/libs/platform",
4 | "lib": {
5 | "entryFile": "src/index.ts"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/libs/platform/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@ng-http/platform",
3 | "version": "0.0.1",
4 | "peerDependencies": {
5 | "@angular/common": "^14.0.0",
6 | "@angular/core": "^14.0.0"
7 | },
8 | "dependencies": {
9 | "tslib": "^2.3.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/libs/platform/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "projectType": "library",
3 | "sourceRoot": "libs/platform/src",
4 | "prefix": "ng-http",
5 | "targets": {
6 | "build": {
7 | "executor": "@nrwl/angular:package",
8 | "outputs": ["dist/libs/platform"],
9 | "options": {
10 | "project": "libs/platform/ng-package.json"
11 | },
12 | "configurations": {
13 | "production": {
14 | "tsConfig": "libs/platform/tsconfig.lib.prod.json"
15 | },
16 | "development": {
17 | "tsConfig": "libs/platform/tsconfig.lib.json"
18 | }
19 | },
20 | "defaultConfiguration": "production"
21 | },
22 | "test": {
23 | "executor": "@nrwl/jest:jest",
24 | "outputs": ["coverage/libs/platform"],
25 | "options": {
26 | "jestConfig": "libs/platform/jest.config.ts",
27 | "passWithNoTests": true
28 | }
29 | },
30 | "lint": {
31 | "executor": "@nrwl/linter:eslint",
32 | "options": {
33 | "lintFilePatterns": ["libs/platform/**/*.ts", "libs/platform/**/*.html"]
34 | }
35 | }
36 | },
37 | "tags": []
38 | }
39 |
--------------------------------------------------------------------------------
/libs/platform/src/index.ts:
--------------------------------------------------------------------------------
1 | export * from './lib/platform.module';
2 | export { platformHttpDynamic } from './lib/platform';
3 | export * from './lib/renderer';
4 |
--------------------------------------------------------------------------------
/libs/platform/src/lib/error-handler.ts:
--------------------------------------------------------------------------------
1 | import { ErrorHandler, Injectable } from '@angular/core';
2 |
3 | @Injectable()
4 | export class HttpErrorHandler implements ErrorHandler {
5 | handleError(error: Error): void {
6 | console.error(error.message, error.stack);
7 | process.exit(0);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/libs/platform/src/lib/loader.ts:
--------------------------------------------------------------------------------
1 | import { ResourceLoader } from '@angular/compiler';
2 | import { readFile } from '@rxnode/fs';
3 | import { map } from 'rxjs/operators';
4 | import { lastValueFrom } from 'rxjs';
5 |
6 | export class HttpResourceLoader implements ResourceLoader {
7 | get(url: string): Promise | string {
8 | return lastValueFrom(
9 | readFile(url).pipe(map((result) => result.toString()))
10 | );
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/libs/platform/src/lib/platform.module.ts:
--------------------------------------------------------------------------------
1 | import {
2 | ApplicationInitStatus,
3 | ApplicationModule,
4 | ApplicationRef,
5 | ErrorHandler,
6 | NgModule,
7 | RendererFactory2,
8 | } from '@angular/core';
9 | import { HttpRendererFactory } from './renderer';
10 | import { HttpErrorHandler } from './error-handler';
11 |
12 | @NgModule({
13 | exports: [ApplicationModule],
14 | providers: [
15 | { provide: RendererFactory2, useClass: HttpRendererFactory },
16 | { provide: ErrorHandler, useClass: HttpErrorHandler },
17 | { provide: ApplicationRef, useClass: ApplicationRef },
18 | { provide: ApplicationInitStatus, useClass: ApplicationInitStatus },
19 | ],
20 | })
21 | export class PlatformModule {}
22 |
--------------------------------------------------------------------------------
/libs/platform/src/lib/platform.ts:
--------------------------------------------------------------------------------
1 | import 'core-js/es/reflect';
2 | import 'zone.js/dist/zone-node';
3 |
4 | import {
5 | COMPILER_OPTIONS,
6 | createPlatformFactory,
7 | Sanitizer,
8 | } from '@angular/core';
9 | import { ɵplatformCoreDynamic as platformCoreDynamic } from '@angular/platform-browser-dynamic';
10 | import { DOCUMENT } from '@angular/common';
11 | import { ElementSchemaRegistry } from '@angular/compiler';
12 |
13 | import { HttpElementSchemaRegistry } from './schema-registry';
14 | import { HttpSanitizer } from './sanitizer';
15 |
16 | const COMMON_PROVIDERS = [
17 | { provide: DOCUMENT, useValue: {} },
18 | { provide: Sanitizer, useClass: HttpSanitizer, deps: [] },
19 | ];
20 |
21 | const COMPILER_PROVIDERS = [
22 | {
23 | provide: COMPILER_OPTIONS,
24 | useValue: {
25 | providers: [
26 | {
27 | provide: ElementSchemaRegistry,
28 | useClass: HttpElementSchemaRegistry,
29 | deps: [],
30 | },
31 | ],
32 | },
33 | multi: true,
34 | },
35 | ];
36 |
37 | export const platformHttpDynamic = createPlatformFactory(
38 | platformCoreDynamic,
39 | 'httpDynamic',
40 | [...COMMON_PROVIDERS, ...COMPILER_PROVIDERS]
41 | );
42 |
--------------------------------------------------------------------------------
/libs/platform/src/lib/renderer.ts:
--------------------------------------------------------------------------------
1 | import {
2 | Injectable,
3 | Renderer2,
4 | RendererFactory2,
5 | RendererStyleFlags2,
6 | RendererType2,
7 | } from '@angular/core';
8 |
9 | @Injectable()
10 | export class HttpRendererFactory implements RendererFactory2 {
11 | protected renderer: Renderer2;
12 |
13 | constructor() {
14 | this.renderer = new HttpRenderer();
15 | }
16 |
17 | // eslint-disable-next-line @typescript-eslint/no-empty-function
18 | end() {}
19 |
20 | createRenderer(hostElement: any, type: RendererType2 | null): Renderer2 {
21 | return this.renderer;
22 | }
23 | }
24 |
25 | export class HttpElement {
26 | [key: string]: any;
27 | public children: HttpElement[] = [];
28 | private readonly classes: string[] = [];
29 | private readonly attrs: Map = new Map();
30 | parent: HttpElement | null = null;
31 | constructor(private name: string) {}
32 |
33 | addClass(className: string) {
34 | this.classes.push(className);
35 | }
36 |
37 | appendChild(child: HttpElement) {
38 | this.children.push(child);
39 | child.parent = this;
40 | }
41 |
42 | insertBefore(newChild: HttpElement, refChild: HttpElement): void {
43 | const index = this.children.indexOf(refChild);
44 |
45 | if (index > -1) {
46 | this.children.splice(index, 0, newChild);
47 | refChild.parent = null;
48 | }
49 | }
50 |
51 | nextSibling(): HttpElement | null {
52 | const parent = this.parent;
53 | if (parent) {
54 | const index = parent.children.indexOf(this);
55 |
56 | return parent.children[index + 1];
57 | }
58 |
59 | return null;
60 | }
61 |
62 | removeAttribute(name: string): void {
63 | this.attrs.delete(name);
64 | }
65 |
66 | removeChild(oldChild: HttpElement): void {
67 | const index = this.children.indexOf(oldChild);
68 | if (index > -1) {
69 | this.children.splice(index, 1);
70 | oldChild.parent = null;
71 | }
72 | }
73 |
74 | removeClass(name: string): void {
75 | const index = this.classes.indexOf(name);
76 |
77 | if (index > -1) {
78 | this.classes.splice(index, 1);
79 | }
80 | }
81 |
82 | // eslint-disable-next-line @typescript-eslint/no-empty-function
83 | removeStyle(style: string, flags?: RendererStyleFlags2): void {}
84 |
85 | setAttribute(name: string, value: string): void {
86 | this.attrs.set(name, value);
87 | }
88 |
89 | setProperty(name: string, value: any): void {
90 | this[name] = value;
91 | }
92 |
93 | // eslint-disable-next-line @typescript-eslint/no-empty-function
94 | setStyle(style: string, value: any, flags?: RendererStyleFlags2): void {}
95 |
96 | setValue(value: string): void {
97 | this.setAttribute('value', value);
98 | }
99 |
100 | toString(): string {
101 | return `<${
102 | this.name
103 | }${this.classesToString()}${this.attrsToString()}>${this.childrenToString()}${
104 | this.name
105 | }>`;
106 | }
107 |
108 | private classesToString() {
109 | if (this.classes.length) {
110 | return ` class="${this.classes.join(' ')}"`;
111 | }
112 |
113 | return '';
114 | }
115 |
116 | private attrsToString() {
117 | if (this.attrs.size) {
118 | return (
119 | ' ' +
120 | [...this.attrs].map(([key, value]) => `${key}="${value}"`).join(' ')
121 | );
122 | }
123 |
124 | return '';
125 | }
126 |
127 | private childrenToString() {
128 | if (this.children.length) {
129 | return this.children.map((child) => child.toString()).join('');
130 | }
131 |
132 | return '';
133 | }
134 | }
135 |
136 | export class TextHttpElement extends HttpElement {
137 | constructor(private text: string) {
138 | super('text');
139 | }
140 |
141 | override toString() {
142 | return this.text;
143 | }
144 | }
145 |
146 | export class CommentHttpElement extends HttpElement {
147 | constructor(private comment: string) {
148 | super('comment');
149 | }
150 |
151 | override toString() {
152 | return '';
153 | }
154 | }
155 |
156 | export class HttpRenderer implements Renderer2 {
157 | destroyNode!: (node: any) => void;
158 |
159 | get data(): { [key: string]: any } {
160 | return {};
161 | }
162 |
163 | createElement(name: string, namespace?: string | null): HttpElement {
164 | return new HttpElement(name);
165 | }
166 |
167 | createText(value: string): any {
168 | return new TextHttpElement(value);
169 | }
170 |
171 | selectRootElement(): HttpElement {
172 | return new HttpElement('root');
173 | }
174 |
175 | addClass(el: HttpElement, name: string): void {
176 | el.addClass(name);
177 | }
178 |
179 | appendChild(parent: HttpElement, newChild: HttpElement): void {
180 | parent.appendChild(newChild);
181 | }
182 |
183 | createComment(value: string): CommentHttpElement {
184 | return new CommentHttpElement(value);
185 | }
186 |
187 | // eslint-disable-next-line @typescript-eslint/no-empty-function
188 | destroy(): void {}
189 |
190 | insertBefore(
191 | parent: HttpElement,
192 | newChild: HttpElement,
193 | refChild: HttpElement
194 | ): void {
195 | parent.insertBefore(newChild, refChild);
196 | }
197 |
198 | listen(
199 | target: any,
200 | eventName: string,
201 | callback: (event: any) => boolean | void
202 | ): () => void {
203 | // eslint-disable-next-line @typescript-eslint/no-empty-function
204 | return function () {};
205 | }
206 |
207 | nextSibling(node: HttpElement): HttpElement | null {
208 | return node.nextSibling();
209 | }
210 |
211 | parentNode(node: HttpElement): HttpElement | null {
212 | return node.parent;
213 | }
214 |
215 | removeAttribute(
216 | el: HttpElement,
217 | name: string,
218 | namespace?: string | null
219 | ): void {
220 | el.removeAttribute(name);
221 | }
222 |
223 | removeChild(parent: HttpElement, oldChild: HttpElement): void {
224 | parent.removeChild(oldChild);
225 | }
226 |
227 | removeClass(el: HttpElement, name: string): void {
228 | el.removeClass(name);
229 | }
230 |
231 | removeStyle(
232 | el: HttpElement,
233 | style: string,
234 | flags?: RendererStyleFlags2
235 | ): void {
236 | el.removeStyle(style, flags);
237 | }
238 |
239 | setAttribute(
240 | el: HttpElement,
241 | name: string,
242 | value: string,
243 | namespace?: string | null
244 | ): void {
245 | el.setAttribute(name, value);
246 | }
247 |
248 | setProperty(el: HttpElement, name: string, value: any): void {
249 | el.setProperty(name, value);
250 | }
251 |
252 | setStyle(
253 | el: HttpElement,
254 | style: string,
255 | value: any,
256 | flags?: RendererStyleFlags2
257 | ): void {
258 | el.setStyle(style, value, flags);
259 | }
260 |
261 | setValue(node: HttpElement, value: string): void {
262 | node.setValue(value);
263 | }
264 | }
265 |
--------------------------------------------------------------------------------
/libs/platform/src/lib/sanitizer.ts:
--------------------------------------------------------------------------------
1 | import { Sanitizer, SecurityContext } from '@angular/core';
2 |
3 | export class HttpSanitizer extends Sanitizer {
4 | sanitize(context: SecurityContext, value: string): string {
5 | return value;
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/libs/platform/src/lib/schema-registry.ts:
--------------------------------------------------------------------------------
1 | import { ElementSchemaRegistry } from '@angular/compiler';
2 | import { SchemaMetadata, SecurityContext } from '@angular/core';
3 |
4 | export class HttpElementSchemaRegistry extends ElementSchemaRegistry {
5 | hasProperty(_tagName: string, _propName: string): boolean {
6 | return true;
7 | }
8 |
9 | hasElement(_tagName: string, _schemaMetas: SchemaMetadata[]): boolean {
10 | return true;
11 | }
12 |
13 | getMappedPropName(propName: string): string {
14 | return propName;
15 | }
16 |
17 | getDefaultComponentElementName(): string {
18 | return 'ng-component';
19 | }
20 |
21 | securityContext(_tagName: string, _propName: string): any {
22 | return SecurityContext.NONE;
23 | }
24 |
25 | validateProperty(_name: string): { error: boolean; msg?: string } {
26 | return { error: false };
27 | }
28 |
29 | validateAttribute(_name: string): { error: boolean; msg?: string } {
30 | return { error: false };
31 | }
32 |
33 | allKnownElementNames(): string[] {
34 | return [];
35 | }
36 |
37 | normalizeAnimationStyleProperty(propName: string): string {
38 | return propName;
39 | }
40 |
41 | normalizeAnimationStyleValue(
42 | _camelCaseProp: string,
43 | _userProvidedProp: string,
44 | val: string | number
45 | ): { error: string; value: string } {
46 | return { error: '', value: val.toString() };
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/libs/platform/src/test-setup.ts:
--------------------------------------------------------------------------------
1 | import 'jest-preset-angular/setup-jest';
2 |
--------------------------------------------------------------------------------
/libs/platform/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig.base.json",
3 | "files": [],
4 | "include": [],
5 | "references": [
6 | {
7 | "path": "./tsconfig.lib.json"
8 | },
9 | {
10 | "path": "./tsconfig.lib.prod.json"
11 | },
12 | {
13 | "path": "./tsconfig.spec.json"
14 | }
15 | ],
16 | "compilerOptions": {
17 | "target": "es2020",
18 | "forceConsistentCasingInFileNames": true,
19 | "strict": true,
20 | "noImplicitOverride": true,
21 | "noPropertyAccessFromIndexSignature": true,
22 | "noImplicitReturns": true,
23 | "noFallthroughCasesInSwitch": true
24 | },
25 | "angularCompilerOptions": {
26 | "enableI18nLegacyMessageIdFormat": false,
27 | "strictInjectionParameters": true,
28 | "strictInputAccessModifiers": true,
29 | "strictTemplates": true
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/libs/platform/tsconfig.lib.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../../dist/out-tsc",
5 | "declaration": true,
6 | "declarationMap": true,
7 | "inlineSources": true,
8 | "types": ["node"]
9 | },
10 | "exclude": [
11 | "src/test-setup.ts",
12 | "**/*.spec.ts",
13 | "jest.config.ts",
14 | "**/*.test.ts"
15 | ],
16 | "include": ["**/*.ts"]
17 | }
18 |
--------------------------------------------------------------------------------
/libs/platform/tsconfig.lib.prod.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.lib.json",
3 | "compilerOptions": {
4 | "declarationMap": false
5 | },
6 | "angularCompilerOptions": {
7 | "compilationMode": "partial"
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/libs/platform/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../../dist/out-tsc",
5 | "module": "commonjs",
6 | "types": ["jest", "node"]
7 | },
8 | "files": ["src/test-setup.ts"],
9 | "include": ["jest.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
10 | }
11 |
--------------------------------------------------------------------------------
/libs/server/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": ["../../.eslintrc.json"],
3 | "ignorePatterns": ["!**/*"],
4 | "overrides": [
5 | {
6 | "files": ["*.ts"],
7 | "extends": [
8 | "plugin:@nrwl/nx/angular",
9 | "plugin:@angular-eslint/template/process-inline-templates"
10 | ],
11 | "rules": {
12 | "@angular-eslint/directive-selector": [
13 | "error",
14 | {
15 | "type": "attribute",
16 | "prefix": "",
17 | "style": "camelCase"
18 | }
19 | ],
20 | "@angular-eslint/component-selector": [
21 | "error",
22 | {
23 | "type": "element",
24 | "prefix": "",
25 | "style": "kebab-case"
26 | }
27 | ]
28 | }
29 | },
30 | {
31 | "files": ["*.html"],
32 | "extends": ["plugin:@nrwl/nx/angular-template"],
33 | "rules": {}
34 | }
35 | ]
36 | }
37 |
--------------------------------------------------------------------------------
/libs/server/README.md:
--------------------------------------------------------------------------------
1 | # server
2 |
3 | This library was generated with [Nx](https://nx.dev).
4 |
5 | ## Running unit tests
6 |
7 | Run `nx test server` to execute the unit tests.
8 |
--------------------------------------------------------------------------------
/libs/server/jest.config.ts:
--------------------------------------------------------------------------------
1 | /* eslint-disable */
2 | export default {
3 | displayName: 'server',
4 | preset: '../../jest.preset.js',
5 | setupFilesAfterEnv: ['/src/test-setup.ts'],
6 | globals: {
7 | 'ts-jest': {
8 | tsconfig: '/tsconfig.spec.json',
9 | stringifyContentPathRegex: '\\.(html|svg)$',
10 | },
11 | },
12 | coverageDirectory: '../../coverage/libs/server',
13 | transform: {
14 | '^.+\\.(ts|mjs|js|html)$': 'jest-preset-angular',
15 | },
16 | transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
17 | snapshotSerializers: [
18 | 'jest-preset-angular/build/serializers/no-ng-attributes',
19 | 'jest-preset-angular/build/serializers/ng-snapshot',
20 | 'jest-preset-angular/build/serializers/html-comment',
21 | ],
22 | };
23 |
--------------------------------------------------------------------------------
/libs/server/ng-package.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3 | "dest": "../../dist/libs/server",
4 | "lib": {
5 | "entryFile": "src/index.ts"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/libs/server/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@ng-http/server",
3 | "version": "0.0.1",
4 | "peerDependencies": {
5 | "@angular/common": "^14.0.0",
6 | "@angular/core": "^14.0.0"
7 | },
8 | "dependencies": {
9 | "tslib": "^2.3.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/libs/server/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "projectType": "library",
3 | "sourceRoot": "libs/server/src",
4 | "prefix": "ng-http",
5 | "targets": {
6 | "build": {
7 | "executor": "@nrwl/angular:package",
8 | "outputs": ["dist/libs/server"],
9 | "options": {
10 | "project": "libs/server/ng-package.json"
11 | },
12 | "configurations": {
13 | "production": {
14 | "tsConfig": "libs/server/tsconfig.lib.prod.json"
15 | },
16 | "development": {
17 | "tsConfig": "libs/server/tsconfig.lib.json"
18 | }
19 | },
20 | "defaultConfiguration": "production"
21 | },
22 | "test": {
23 | "executor": "@nrwl/jest:jest",
24 | "outputs": ["coverage/libs/server"],
25 | "options": {
26 | "jestConfig": "libs/server/jest.config.ts",
27 | "passWithNoTests": true
28 | }
29 | },
30 | "lint": {
31 | "executor": "@nrwl/linter:eslint",
32 | "options": {
33 | "lintFilePatterns": ["libs/server/**/*.ts", "libs/server/**/*.html"]
34 | }
35 | }
36 | },
37 | "tags": []
38 | }
39 |
--------------------------------------------------------------------------------
/libs/server/src/index.ts:
--------------------------------------------------------------------------------
1 | export * from './lib/controllers/content-type-html.directive';
2 | export * from './lib/get/get.component';
3 | export * from './lib/server/server.component';
4 |
5 | export * from './lib/server.module';
6 | export * from './lib/controller';
7 |
--------------------------------------------------------------------------------
/libs/server/src/lib/controller.ts:
--------------------------------------------------------------------------------
1 | import { Observable } from 'rxjs';
2 | import { IncomingMessage, ServerResponse } from 'http';
3 |
4 | export abstract class Controller {
5 | abstract handle(
6 | req: IncomingMessage,
7 | res: ServerResponse
8 | ): void | Promise | Observable;
9 | }
10 |
--------------------------------------------------------------------------------
/libs/server/src/lib/controllers/content-type-html.directive.spec.ts:
--------------------------------------------------------------------------------
1 | import { ContentTypeHtmlDirective } from './content-type-html.directive';
2 |
3 | describe('ContentTypeHtmlDirective', () => {
4 | it('should create an instance', () => {
5 | const directive = new ContentTypeHtmlDirective();
6 | expect(directive).toBeTruthy();
7 | });
8 | });
9 |
--------------------------------------------------------------------------------
/libs/server/src/lib/controllers/content-type-html.directive.ts:
--------------------------------------------------------------------------------
1 | import { Directive, ElementRef, forwardRef } from '@angular/core';
2 | import { Controller } from '../controller';
3 | import { HttpElement } from '@ng-http/platform';
4 | import { IncomingMessage, ServerResponse } from 'http';
5 | import { Observable } from 'rxjs';
6 |
7 | @Directive({
8 | selector: '[contentType="text/html"]',
9 | providers: [
10 | {
11 | provide: Controller,
12 | useExisting: forwardRef(() => ContentTypeHtmlDirective),
13 | },
14 | ],
15 | })
16 | export class ContentTypeHtmlDirective extends Controller {
17 | constructor(private elementRef: ElementRef) {
18 | super();
19 | }
20 |
21 | handle(
22 | req: IncomingMessage,
23 | res: ServerResponse
24 | ): void | Promise | Observable {
25 | res.setHeader('Content-Type', 'text/html');
26 |
27 | res.end(
28 | this.elementRef.nativeElement.children.map((el) => el.toString()).join('')
29 | );
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/libs/server/src/lib/get/get.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { GetComponent } from './get.component';
4 |
5 | describe('GetComponent', () => {
6 | let component: GetComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async () => {
10 | await TestBed.configureTestingModule({
11 | declarations: [GetComponent],
12 | }).compileComponents();
13 | });
14 |
15 | beforeEach(() => {
16 | fixture = TestBed.createComponent(GetComponent);
17 | component = fixture.componentInstance;
18 | fixture.detectChanges();
19 | });
20 |
21 | it('should create', () => {
22 | expect(component).toBeTruthy();
23 | });
24 | });
25 |
--------------------------------------------------------------------------------
/libs/server/src/lib/get/get.component.ts:
--------------------------------------------------------------------------------
1 | import { ChangeDetectionStrategy, Component, Input, Self } from '@angular/core';
2 | import { concatMap, filter } from 'rxjs/operators';
3 | import { Server } from '@rxnode/http';
4 | import { Controller } from '../controller';
5 | import { defer } from 'rxjs';
6 |
7 | @Component({
8 | selector: 'get',
9 | template: `
10 |
11 |
12 | `,
13 | changeDetection: ChangeDetectionStrategy.OnPush,
14 | })
15 | export class GetComponent {
16 | @Input() url!: string;
17 |
18 | messages$ = this.server.pipe(
19 | filter(
20 | ([req]) =>
21 | !!this.url && req.url?.indexOf(this.url) === 0 && req.method === 'GET'
22 | ),
23 | concatMap(([req, res]) =>
24 | defer(() => this.controller.handle(req, res) ?? Promise.resolve())
25 | )
26 | );
27 |
28 | constructor(private server: Server, @Self() private controller: Controller) {}
29 | }
30 |
--------------------------------------------------------------------------------
/libs/server/src/lib/server.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { CommonModule } from '@angular/common';
3 | import { ServerComponent } from './server/server.component';
4 | import { GetComponent } from './get/get.component';
5 | import { ContentTypeHtmlDirective } from './controllers/content-type-html.directive';
6 |
7 | @NgModule({
8 | imports: [CommonModule],
9 | declarations: [ServerComponent, GetComponent, ContentTypeHtmlDirective],
10 | exports: [ServerComponent, GetComponent, ContentTypeHtmlDirective],
11 | })
12 | export class ServerModule {}
13 |
--------------------------------------------------------------------------------
/libs/server/src/lib/server/server.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/libs/server/src/lib/server/server.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { ServerComponent } from './server.component';
4 |
5 | describe('ServerComponent', () => {
6 | let component: ServerComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async () => {
10 | await TestBed.configureTestingModule({
11 | declarations: [ServerComponent],
12 | }).compileComponents();
13 | });
14 |
15 | beforeEach(() => {
16 | fixture = TestBed.createComponent(ServerComponent);
17 | component = fixture.componentInstance;
18 | fixture.detectChanges();
19 | });
20 |
21 | it('should create', () => {
22 | expect(component).toBeTruthy();
23 | });
24 | });
25 |
--------------------------------------------------------------------------------
/libs/server/src/lib/server/server.component.ts:
--------------------------------------------------------------------------------
1 | import {
2 | ChangeDetectionStrategy,
3 | Component,
4 | forwardRef,
5 | Input,
6 | } from '@angular/core';
7 | import { Server } from '@rxnode/http';
8 | import { EMPTY, Observable } from 'rxjs';
9 | import { tap } from 'rxjs/operators';
10 | import { ServerOptions } from 'http';
11 |
12 | @Component({
13 | selector: 'server',
14 | templateUrl: './server.component.html',
15 | changeDetection: ChangeDetectionStrategy.OnPush,
16 | providers: [
17 | { provide: Server, useExisting: forwardRef(() => ServerComponent) },
18 | ],
19 | })
20 | export class ServerComponent extends Server {
21 | public listen$: Observable = EMPTY;
22 |
23 | private _port!: number;
24 |
25 | constructor() {
26 | super();
27 | }
28 |
29 | @Input() set port(value: number) {
30 | if (this._port !== value) {
31 | this._port = value;
32 | this.listen$ = this.listen(value).pipe(
33 | tap(() => console.log(`Server stated on port ${value}`))
34 | );
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/libs/server/src/test-setup.ts:
--------------------------------------------------------------------------------
1 | import 'jest-preset-angular/setup-jest';
2 |
--------------------------------------------------------------------------------
/libs/server/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig.base.json",
3 | "files": [],
4 | "include": [],
5 | "references": [
6 | {
7 | "path": "./tsconfig.lib.json"
8 | },
9 | {
10 | "path": "./tsconfig.lib.prod.json"
11 | },
12 | {
13 | "path": "./tsconfig.spec.json"
14 | }
15 | ],
16 | "compilerOptions": {
17 | "target": "es2020",
18 | "forceConsistentCasingInFileNames": true,
19 | "strict": true,
20 | "noImplicitOverride": true,
21 | "noPropertyAccessFromIndexSignature": true,
22 | "noImplicitReturns": true,
23 | "noFallthroughCasesInSwitch": true
24 | },
25 | "angularCompilerOptions": {
26 | "enableI18nLegacyMessageIdFormat": false,
27 | "strictInjectionParameters": true,
28 | "strictInputAccessModifiers": true,
29 | "strictTemplates": true
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/libs/server/tsconfig.lib.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../../dist/out-tsc",
5 | "declaration": true,
6 | "declarationMap": true,
7 | "inlineSources": true,
8 | "types": []
9 | },
10 | "exclude": [
11 | "src/test-setup.ts",
12 | "**/*.spec.ts",
13 | "jest.config.ts",
14 | "**/*.test.ts"
15 | ],
16 | "include": ["**/*.ts"]
17 | }
18 |
--------------------------------------------------------------------------------
/libs/server/tsconfig.lib.prod.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.lib.json",
3 | "compilerOptions": {
4 | "declarationMap": false
5 | },
6 | "angularCompilerOptions": {
7 | "compilationMode": "partial"
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/libs/server/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../../dist/out-tsc",
5 | "module": "commonjs",
6 | "types": ["jest", "node"]
7 | },
8 | "files": ["src/test-setup.ts"],
9 | "include": ["jest.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
10 | }
11 |
--------------------------------------------------------------------------------
/nx.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/nx/schemas/nx-schema.json",
3 | "npmScope": "ng-http",
4 | "affected": {
5 | "defaultBase": "main"
6 | },
7 | "implicitDependencies": {
8 | "package.json": {
9 | "dependencies": "*",
10 | "devDependencies": "*"
11 | },
12 | ".eslintrc.json": "*"
13 | },
14 | "tasksRunnerOptions": {
15 | "default": {
16 | "runner": "@nrwl/nx-cloud",
17 | "options": {
18 | "cacheableOperations": [
19 | "build",
20 | "lint",
21 | "test",
22 | "e2e"
23 | ],
24 | "accessToken": "ZTA2ZDQyNzgtZWUyOC00YjZlLWIzNzYtZmEwMGY0ZmRjNmM1fHJlYWQtd3JpdGU="
25 | }
26 | }
27 | },
28 | "targetDefaults": {
29 | "build": {
30 | "dependsOn": [
31 | "^build"
32 | ]
33 | }
34 | },
35 | "generators": {
36 | "@nrwl/angular:application": {
37 | "style": "css",
38 | "linter": "eslint",
39 | "unitTestRunner": "jest",
40 | "e2eTestRunner": "cypress"
41 | },
42 | "@nrwl/angular:library": {
43 | "linter": "eslint",
44 | "unitTestRunner": "jest"
45 | },
46 | "@nrwl/angular:component": {
47 | "style": "css"
48 | }
49 | },
50 | "defaultProject": "sandbox"
51 | }
52 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ng-http",
3 | "version": "0.0.0",
4 | "license": "MIT",
5 | "scripts": {
6 | "start": "nx serve",
7 | "build": "nx build",
8 | "test": "nx test",
9 | "postinstall": "ngcc --properties es2020 browser module main"
10 | },
11 | "private": true,
12 | "devDependencies": {
13 | "@angular-devkit/build-angular": "~14.2.0",
14 | "@angular-eslint/eslint-plugin": "~14.0.0",
15 | "@angular-eslint/eslint-plugin-template": "~14.0.0",
16 | "@angular-eslint/template-parser": "~14.0.0",
17 | "@angular/cli": "~14.2.0",
18 | "@angular/compiler-cli": "~14.2.0",
19 | "@angular/language-service": "~14.2.0",
20 | "@nrwl/angular": "14.6.4",
21 | "@nrwl/cli": "14.6.4",
22 | "@nrwl/cypress": "14.6.4",
23 | "@nrwl/eslint-plugin-nx": "14.6.4",
24 | "@nrwl/jest": "14.6.4",
25 | "@nrwl/linter": "14.6.4",
26 | "@nrwl/nx-cloud": "latest",
27 | "@nrwl/workspace": "14.6.4",
28 | "@rxnode/fs": "1.0.0",
29 | "@rxnode/http": "1.0.0",
30 | "@types/jest": "28.1.1",
31 | "@types/node": "16.11.7",
32 | "@typescript-eslint/eslint-plugin": "~5.33.1",
33 | "@typescript-eslint/parser": "~5.33.1",
34 | "cypress": "^10.2.0",
35 | "eslint": "~8.15.0",
36 | "eslint-config-prettier": "8.1.0",
37 | "eslint-plugin-cypress": "^2.10.3",
38 | "jest": "28.1.1",
39 | "jest-environment-jsdom": "28.1.1",
40 | "jest-preset-angular": "~12.2.0",
41 | "ng-packagr": "~14.2.0",
42 | "nx": "14.6.4",
43 | "postcss": "^8.4.5",
44 | "postcss-import": "~14.1.0",
45 | "postcss-preset-env": "~7.5.0",
46 | "postcss-url": "~10.1.3",
47 | "prettier": "^2.6.2",
48 | "ts-jest": "28.0.5",
49 | "ts-node": "10.9.1",
50 | "typescript": "~4.7.2"
51 | },
52 | "dependencies": {
53 | "@angular/animations": "~14.2.0",
54 | "@angular/common": "~14.2.0",
55 | "@angular/compiler": "~14.2.0",
56 | "@angular/core": "~14.2.0",
57 | "@angular/forms": "~14.2.0",
58 | "@angular/platform-browser": "~14.2.0",
59 | "@angular/platform-browser-dynamic": "~14.2.0",
60 | "@angular/router": "~14.2.0",
61 | "rxjs": "~7.5.0",
62 | "tslib": "^2.3.0",
63 | "zone.js": "~0.11.4"
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/tools/generators/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IKatsuba/ng-http/68416c71013291202b2c9261c78668365aaab0f5/tools/generators/.gitkeep
--------------------------------------------------------------------------------
/tools/tsconfig.tools.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.base.json",
3 | "compilerOptions": {
4 | "outDir": "../dist/out-tsc/tools",
5 | "rootDir": ".",
6 | "module": "commonjs",
7 | "target": "es5",
8 | "types": ["node"],
9 | "importHelpers": false
10 | },
11 | "include": ["**/*.ts"]
12 | }
13 |
--------------------------------------------------------------------------------
/tsconfig.base.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "rootDir": ".",
5 | "sourceMap": true,
6 | "declaration": false,
7 | "moduleResolution": "node",
8 | "emitDecoratorMetadata": true,
9 | "experimentalDecorators": true,
10 | "importHelpers": true,
11 | "target": "es2015",
12 | "module": "esnext",
13 | "lib": ["es2017", "dom"],
14 | "skipLibCheck": true,
15 | "skipDefaultLibCheck": true,
16 | "baseUrl": ".",
17 | "paths": {
18 | "@ng-http/platform": ["libs/platform/src/index.ts"],
19 | "@ng-http/server": ["libs/server/src/index.ts"]
20 | }
21 | },
22 | "exclude": ["node_modules", "tmp"]
23 | }
24 |
--------------------------------------------------------------------------------
/workspace.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/nx/schemas/workspace-schema.json",
3 | "version": 2,
4 | "projects": {
5 | "platform": "libs/platform",
6 | "sandbox": "apps/sandbox",
7 | "server": "libs/server"
8 | }
9 | }
10 |
--------------------------------------------------------------------------------