This repository has been archived by the owner on Nov 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mirror socket-engine from angular/universal/issues/1000.
- Loading branch information
bbortt
committed
Aug 6, 2018
1 parent
fe5b14a
commit 2b8f92c
Showing
30 changed files
with
2,640 additions
and
2,171 deletions.
There are no files selected for viewing
4,163 changes: 2,072 additions & 2,091 deletions
4,163
core-server/authorization-server/src/main/webapp/package-lock.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 0 additions & 42 deletions
42
core-server/authorization-server/src/main/webapp/server.old.js
This file was deleted.
Oops, something went wrong.
42 changes: 6 additions & 36 deletions
42
core-server/authorization-server/src/main/webapp/server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,9 @@ | ||
import 'zone.js/dist/zone-node'; | ||
import 'reflect-metadata'; | ||
|
||
import * as express from 'express'; | ||
import {join} from 'path'; | ||
import {ngExpressEngine} from '@nguniversal/express-engine'; | ||
import {provideModuleMap} from '@nguniversal/module-map-ngfactory-loader'; | ||
|
||
const app = express(); | ||
|
||
const PORT = process.env.PORT || 4000; | ||
const DIST_FOLDER = join(process.cwd(), 'dist'); | ||
// TODO: Install the latest stable version as soon as the pull-request is merged | ||
// --> https://github.com/angular/universal/pull/999 | ||
import * as socketEngine from './vendor/socket-engine'; | ||
// const socketEngine = require('@nguniversal/socket-engine'); | ||
|
||
// * NOTE :: leave this as require() since this file is built Dynamically from webpack | ||
const {AppServerModuleNgFactory, LAZY_MODULE_MAP} = require('./dist/server/main'); | ||
|
||
app.engine('html', ngExpressEngine({ | ||
bootstrap: AppServerModuleNgFactory, | ||
providers: [ | ||
provideModuleMap(LAZY_MODULE_MAP) | ||
] | ||
})); | ||
|
||
app.set('view engine', 'html'); | ||
app.set('views', join(DIST_FOLDER, 'browser')); | ||
|
||
// TODO: proxy backend requests | ||
app.get('/api/*', (req, res) => { | ||
res.status(404).send('data requests are not supported'); | ||
}); | ||
|
||
app.get('*.*', express.static(join(DIST_FOLDER, 'browser'))); | ||
|
||
app.get('*', (req, res) => { | ||
res.render('index', {req}); | ||
}); | ||
|
||
app.listen(PORT, () => { | ||
console.log(`Node server listening on http://localhost:${PORT}`); | ||
}); | ||
socketEngine.startSocketEngine(AppServerModuleNgFactory); |
11 changes: 11 additions & 0 deletions
11
core-server/authorization-server/src/main/webapp/vendor/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# angular / universal / socket-engine | ||
|
||
This vendor packages mirror the repository at [commit ea6f7b13b70c40b55ce72bd549e2dfb56ca146db](https://github.com/angular/universal/commit/ea6f7b13b70c40b55ce72bd549e2dfb56ca146db). Local paths (imports) were adapted accordingly. | ||
|
||
## Bugs and replacement | ||
|
||
The engine is still experimental and contains some bugs. The [major bug]([https://github.com/angular/universal/pull/1003]) depends on (bazel)[https://github.com/bazelbuild/rules_typescript/issues/211]. Once the PR is merged you could install those libraries via NPM. | ||
|
||
## Future installation | ||
|
||
Once the module is merged you can install it as following: `npm install @nguniversal/socket-engine @nguniversal/common --save` |
12 changes: 12 additions & 0 deletions
12
core-server/authorization-server/src/main/webapp/vendor/common/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Angular Universal Common Module | ||
|
||
This is the common Angular Universal module that is common across server-side rendering app | ||
irrespective of the rendering engine. | ||
|
||
The package can be installed using: | ||
|
||
`npm install @nguniversal/common --save` | ||
|
||
## TransferHttpCacheModule | ||
|
||
Moved to [/docs/transfer-http.md](https://github.com/angular/universal/tree/master/docs/transfer-http.md) |
12 changes: 12 additions & 0 deletions
12
core-server/authorization-server/src/main/webapp/vendor/common/engine/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load("//tools:defaults.bzl", "ng_module") | ||
|
||
ng_module( | ||
name = "engine", | ||
srcs = glob([ | ||
"src/*.ts", | ||
"*.ts", | ||
]), | ||
module_name = "@nguniversal/common/engine", | ||
) |
8 changes: 8 additions & 0 deletions
8
core-server/authorization-server/src/main/webapp/vendor/common/engine/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
export * from './public_api'; |
10 changes: 10 additions & 0 deletions
10
core-server/authorization-server/src/main/webapp/vendor/common/engine/private_api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
export { FileLoader as ɵFileLoader, CommonEngine as ɵCommonEngine, | ||
RenderOptions as ɵRenderOptions } from './src/index'; |
8 changes: 8 additions & 0 deletions
8
core-server/authorization-server/src/main/webapp/vendor/common/engine/public_api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
export * from './private_api'; |
92 changes: 92 additions & 0 deletions
92
core-server/authorization-server/src/main/webapp/vendor/common/engine/src/engine.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
import {ResourceLoader} from '@angular/compiler'; | ||
import {Compiler, Type, NgModuleFactory, CompilerFactory, StaticProvider} from '@angular/core'; | ||
import {INITIAL_CONFIG, renderModuleFactory, platformDynamicServer} from '@angular/platform-server'; | ||
import * as fs from 'fs'; | ||
|
||
import {FileLoader} from './file-loader'; | ||
import {RenderOptions} from './interfaces'; | ||
|
||
/** | ||
* A common rendering engine utility. This abstracts the logic | ||
* for handling the platformServer compiler, the module cache, and | ||
* the document loader | ||
*/ | ||
export class CommonEngine { | ||
|
||
/** Return an instance of the platformServer compiler */ | ||
getCompiler(): Compiler { | ||
const compilerFactory: CompilerFactory = platformDynamicServer().injector.get(CompilerFactory); | ||
return compilerFactory.createCompiler([ | ||
{providers: [{provide: ResourceLoader, useClass: FileLoader, deps: []}]} | ||
]); | ||
} | ||
|
||
private factoryCacheMap = new Map<Type<{}>, NgModuleFactory<{}>>(); | ||
private templateCache: {[key: string]: string} = {}; | ||
|
||
constructor(private moduleOrFactory: Type<{}> | NgModuleFactory<{}>, | ||
private providers: StaticProvider[] = []) {} | ||
|
||
/** | ||
* Render an HTML document for a specific URL with specified | ||
* render options | ||
*/ | ||
async render(opts: RenderOptions): Promise<string> { | ||
// if opts.document dosen't exist then opts.documentFilePath must | ||
const doc = opts.document || await this.getDocument(opts!.documentFilePath as string); | ||
const extraProviders = [ | ||
...(opts.providers || []), | ||
...(this.providers || []), | ||
{ | ||
provide: INITIAL_CONFIG, | ||
useValue: { | ||
document: doc, | ||
url: opts.url | ||
} | ||
} | ||
]; | ||
|
||
const factory = await this.getFactory(); | ||
return renderModuleFactory(factory, {extraProviders}); | ||
} | ||
|
||
/** Return the factory for a given engine instance */ | ||
getFactory(): Promise<NgModuleFactory<{}>> { | ||
// If module has been compiled AoT | ||
const moduleOrFactory = this.moduleOrFactory; | ||
if (moduleOrFactory instanceof NgModuleFactory) { | ||
return Promise.resolve(moduleOrFactory); | ||
} else { | ||
// we're in JIT mode | ||
let moduleFactory = this.factoryCacheMap.get(moduleOrFactory); | ||
|
||
// If module factory is cached | ||
if (moduleFactory) { | ||
return Promise.resolve(moduleFactory); | ||
} | ||
|
||
// Compile the module and cache it | ||
return this.getCompiler().compileModuleAsync(moduleOrFactory) | ||
.then((factory) => { | ||
this.factoryCacheMap.set(moduleOrFactory, factory); | ||
return factory; | ||
}); | ||
} | ||
} | ||
|
||
/** Retrieve the document from the cache or the filesystem */ | ||
private getDocument(filePath: string): Promise<string> { | ||
const doc = this.templateCache[filePath] = this.templateCache[filePath] || | ||
fs.readFileSync(filePath).toString(); | ||
|
||
// As promise so we can change the API later without breaking | ||
return Promise.resolve(doc); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
core-server/authorization-server/src/main/webapp/vendor/common/engine/src/file-loader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
import * as fs from 'fs'; | ||
import { ResourceLoader } from '@angular/compiler'; | ||
|
||
/** ResourceLoader implementation for loading files */ | ||
export class FileLoader implements ResourceLoader { | ||
get(url: string): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
fs.readFile(url, (err: NodeJS.ErrnoException, buffer: Buffer) => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
|
||
resolve(buffer.toString()); | ||
}); | ||
}); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
core-server/authorization-server/src/main/webapp/vendor/common/engine/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
export * from './interfaces'; | ||
export * from './file-loader'; | ||
export * from './engine'; |
17 changes: 17 additions & 0 deletions
17
core-server/authorization-server/src/main/webapp/vendor/common/engine/src/interfaces.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
import {NgModuleFactory, StaticProvider, Type} from '@angular/core'; | ||
|
||
/** These are the allowed options for the render */ | ||
export interface RenderOptions { | ||
bootstrap: Type<{}> | NgModuleFactory<{}>; | ||
providers?: StaticProvider[]; | ||
url?: string; | ||
document?: string; | ||
documentFilePath?: string; | ||
} |
8 changes: 8 additions & 0 deletions
8
core-server/authorization-server/src/main/webapp/vendor/common/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
export * from './public_api'; |
8 changes: 8 additions & 0 deletions
8
core-server/authorization-server/src/main/webapp/vendor/common/private_api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
export { TransferHttpCacheInterceptor as ɵTransferHttpCacheInterceptor } from './src/transfer_http'; |
10 changes: 10 additions & 0 deletions
10
core-server/authorization-server/src/main/webapp/vendor/common/public_api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
export { TransferHttpCacheModule } from './src/transfer_http'; | ||
export { StateTransferInitializerModule } from './src/state-transfer-initializer/module'; | ||
export * from './private_api'; |
13 changes: 13 additions & 0 deletions
13
...n-server/src/main/webapp/vendor/common/src/state-transfer-initializer/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# State Transfer Initializer | ||
Delays the app bootstrap process to ensure that the DOM content is loaded before state transfer initilization | ||
|
||
Simply import the module into your project and you will no longer need to wrap your component bootstrap function in an `DOMContentLoaded` callback | ||
|
||
``` | ||
import { StateTransferInitializerModule } from '@nguniversal/common' | ||
@NgModule({ | ||
imports: [ StateTransferInitializerModule ] | ||
}) | ||
export class AppModule{} | ||
``` |
28 changes: 28 additions & 0 deletions
28
...thorization-server/src/main/webapp/vendor/common/src/state-transfer-initializer/module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import { NgModule, APP_INITIALIZER } from '@angular/core'; | ||
import { DOCUMENT } from '@angular/common'; | ||
|
||
export function domContentLoadedFactory(doc: Document) { | ||
return () => new Promise ((resolve, _reject) => { | ||
const contentLoaded = () => { | ||
doc.removeEventListener('DOMContentLoaded', contentLoaded); | ||
resolve(); | ||
}; | ||
doc.addEventListener('DOMContentLoaded', contentLoaded); | ||
}); | ||
} | ||
|
||
|
||
@NgModule({ | ||
providers: [ | ||
{provide: APP_INITIALIZER, multi: true, useFactory: domContentLoadedFactory, deps: [DOCUMENT]}, | ||
] | ||
}) | ||
export class StateTransferInitializerModule {} |
Oops, something went wrong.