@nguniversal/aspnetcore-engine
Advanced tools
Comparing version 1.0.0-beta.1 to 1.0.0-beta.2
12
index.js
@@ -1,4 +0,10 @@ | ||
export { ngAspnetCoreEngine } from './src/main'; | ||
export { createTransferScript } from './src/create-transfer-script'; | ||
export { REQUEST, ORIGIN_URL } from './src/tokens'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var main_1 = require("./src/main"); | ||
exports.ngAspnetCoreEngine = main_1.ngAspnetCoreEngine; | ||
var create_transfer_script_1 = require("./src/create-transfer-script"); | ||
exports.createTransferScript = create_transfer_script_1.createTransferScript; | ||
var tokens_1 = require("./src/tokens"); | ||
exports.REQUEST = tokens_1.REQUEST; | ||
exports.ORIGIN_URL = tokens_1.ORIGIN_URL; | ||
//# sourceMappingURL=index.js.map |
@@ -5,3 +5,3 @@ { | ||
"types": "dist/index.d.ts", | ||
"version": "1.0.0-beta.1", | ||
"version": "1.0.0-beta.2", | ||
"description": "ASP.NET Core Engine for running Server Angular Apps", | ||
@@ -8,0 +8,0 @@ "homepage": "https://github.com/angular/universal", |
@@ -1,4 +0,7 @@ | ||
export function createTransferScript(transferData) { | ||
return `<script>window['TRANSFER_CACHE'] = ${JSON.stringify(transferData)};</script>`; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function createTransferScript(transferData) { | ||
return "<script>window['TRANSFER_CACHE'] = " + JSON.stringify(transferData) + ";</script>"; | ||
} | ||
exports.createTransferScript = createTransferScript; | ||
//# sourceMappingURL=create-transfer-script.js.map |
@@ -1,7 +0,11 @@ | ||
import * as fs from 'fs'; | ||
export class FileLoader { | ||
get(url) { | ||
return new Promise((resolve, reject) => { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var fs = require("fs"); | ||
var FileLoader = (function () { | ||
function FileLoader() { | ||
} | ||
FileLoader.prototype.get = function (url) { | ||
return new Promise(function (resolve, reject) { | ||
// install node types | ||
fs.readFile(url, (err, buffer) => { | ||
fs.readFile(url, function (err, buffer) { | ||
if (err) { | ||
@@ -13,4 +17,6 @@ return reject(err); | ||
}); | ||
} | ||
} | ||
}; | ||
return FileLoader; | ||
}()); | ||
exports.FileLoader = FileLoader; | ||
//# sourceMappingURL=file-loader.js.map |
@@ -0,2 +1,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
; | ||
//# sourceMappingURL=engine-options.js.map |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=request-params.js.map |
107
src/main.js
@@ -1,27 +0,29 @@ | ||
import { NgModuleFactory, ApplicationRef, CompilerFactory } from '@angular/core'; | ||
import { platformServer, platformDynamicServer, PlatformState, INITIAL_CONFIG } from '@angular/platform-server'; | ||
import { ResourceLoader } from '@angular/compiler'; | ||
import { REQUEST, ORIGIN_URL } from './tokens'; | ||
import { FileLoader } from './file-loader'; | ||
import 'rxjs/add/operator/filter'; | ||
import 'rxjs/add/operator/first'; | ||
export function ngAspnetCoreEngine(options) { | ||
options.providers = options.providers || []; | ||
const compilerFactory = platformDynamicServer().injector.get(CompilerFactory); | ||
const compiler = compilerFactory.createCompiler([ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var core_1 = require("@angular/core"); | ||
var platform_server_1 = require("@angular/platform-server"); | ||
var compiler_1 = require("@angular/compiler"); | ||
var tokens_1 = require("./tokens"); | ||
var file_loader_1 = require("./file-loader"); | ||
require("rxjs/add/operator/filter"); | ||
require("rxjs/add/operator/first"); | ||
function ngAspnetCoreEngine(options) { | ||
var compilerFactory = platform_server_1.platformDynamicServer().injector.get(core_1.CompilerFactory); | ||
var compiler = compilerFactory.createCompiler([ | ||
{ | ||
providers: [ | ||
{ provide: ResourceLoader, useClass: FileLoader } | ||
{ provide: compiler_1.ResourceLoader, useClass: file_loader_1.FileLoader } | ||
] | ||
} | ||
]); | ||
return new Promise((resolve, reject) => { | ||
return new Promise(function (resolve, reject) { | ||
try { | ||
const moduleOrFactory = options.ngModule; | ||
var moduleOrFactory = options.ngModule; | ||
if (!moduleOrFactory) { | ||
throw new Error('You must pass in a NgModule or NgModuleFactory to be bootstrapped'); | ||
} | ||
const extraProviders = options.providers.concat(options.providers, [ | ||
options.providers = options.providers || []; | ||
var extraProviders = options.providers.concat(options.providers, [ | ||
{ | ||
provide: INITIAL_CONFIG, | ||
provide: platform_server_1.INITIAL_CONFIG, | ||
useValue: { | ||
@@ -33,38 +35,38 @@ document: options.appSelector, | ||
{ | ||
provide: ORIGIN_URL, | ||
provide: tokens_1.ORIGIN_URL, | ||
useValue: options.request.origin | ||
}, { | ||
provide: REQUEST, | ||
provide: tokens_1.REQUEST, | ||
useValue: options.request.data.request | ||
} | ||
]); | ||
const platform = platformServer(extraProviders); | ||
var platform_1 = platform_server_1.platformServer(extraProviders); | ||
getFactory(moduleOrFactory, compiler) | ||
.then((factory) => { | ||
return platform.bootstrapModuleFactory(factory).then((moduleRef) => { | ||
const state = moduleRef.injector.get(PlatformState); | ||
const appRef = moduleRef.injector.get(ApplicationRef); | ||
.then(function (factory) { | ||
return platform_1.bootstrapModuleFactory(factory).then(function (moduleRef) { | ||
var state = moduleRef.injector.get(platform_server_1.PlatformState); | ||
var appRef = moduleRef.injector.get(core_1.ApplicationRef); | ||
appRef.isStable | ||
.filter((isStable) => isStable) | ||
.filter(function (isStable) { return isStable; }) | ||
.first() | ||
.subscribe(() => { | ||
.subscribe(function () { | ||
// Fire the TransferState Cache | ||
const bootstrap = moduleRef.instance['ngOnBootstrap']; | ||
var bootstrap = moduleRef.instance.ngOnBootstrap; | ||
bootstrap && bootstrap(); | ||
// The parse5 Document itself | ||
const AST_DOCUMENT = state.getDocument(); | ||
var AST_DOCUMENT = state.getDocument(); | ||
// Strip out the Angular application | ||
const htmlDoc = state.renderToString(); | ||
const APP_HTML = htmlDoc.substring(htmlDoc.indexOf('<body>') + 6, htmlDoc.indexOf('</body>')); | ||
var htmlDoc = state.renderToString(); | ||
var APP_HTML = htmlDoc.substring(htmlDoc.indexOf('<body>') + 6, htmlDoc.indexOf('</body>')); | ||
// Strip out Styles / Meta-tags / Title | ||
// const STYLES = []; | ||
const META = []; | ||
const LINKS = []; | ||
let TITLE = ''; | ||
let STYLES_STRING = htmlDoc.substring(htmlDoc.indexOf('<style ng-transition'), htmlDoc.lastIndexOf('</style>') + 8); | ||
var META = []; | ||
var LINKS = []; | ||
var TITLE = ''; | ||
var STYLES_STRING = htmlDoc.substring(htmlDoc.indexOf('<style ng-transition'), htmlDoc.lastIndexOf('</style>') + 8); | ||
// STYLES_STRING = STYLES_STRING.replace(/\s/g, '').replace('<styleng-transition', '<style ng-transition'); | ||
const HEAD = AST_DOCUMENT.head; | ||
let count = 0; | ||
for (let i = 0; i < HEAD.children.length; i++) { | ||
let element = HEAD.children[i]; | ||
var HEAD = AST_DOCUMENT.head; | ||
var count = 0; | ||
for (var i = 0; i < HEAD.children.length; i++) { | ||
var element = HEAD.children[i]; | ||
if (element.name === 'title') { | ||
@@ -87,18 +89,18 @@ TITLE = element.children[0].data; | ||
count = count + 1; | ||
let metaString = '<meta'; | ||
for (let key in element.attribs) { | ||
var metaString = '<meta'; | ||
for (var key in element.attribs) { | ||
if (key) { | ||
metaString += ` ${key}="${element.attribs[key]}"`; | ||
metaString += " " + key + "=\"" + element.attribs[key] + "\""; | ||
} | ||
} | ||
META.push(`${metaString} />\n`); | ||
META.push(metaString + " />\n"); | ||
} | ||
if (element.name === 'link') { | ||
let linkString = '<link'; | ||
for (let key in element.attribs) { | ||
var linkString = '<link'; | ||
for (var key in element.attribs) { | ||
if (key) { | ||
linkString += ` ${key}="${element.attribs[key]}"`; | ||
linkString += " " + key + "=\"" + element.attribs[key] + "\""; | ||
} | ||
} | ||
LINKS.push(`${linkString} />\n`); | ||
LINKS.push(linkString + " />\n"); | ||
} | ||
@@ -117,3 +119,3 @@ } | ||
moduleRef.destroy(); | ||
}, (err) => { | ||
}, function (err) { | ||
reject(err); | ||
@@ -129,8 +131,9 @@ }); | ||
} | ||
exports.ngAspnetCoreEngine = ngAspnetCoreEngine; | ||
/* ********************** Private / Internal ****************** */ | ||
const factoryCacheMap = new Map(); | ||
var factoryCacheMap = new Map(); | ||
function getFactory(moduleOrFactory, compiler) { | ||
return new Promise((resolve, reject) => { | ||
return new Promise(function (resolve, reject) { | ||
// If module has been compiled AoT | ||
if (moduleOrFactory instanceof NgModuleFactory) { | ||
if (moduleOrFactory instanceof core_1.NgModuleFactory) { | ||
resolve(moduleOrFactory); | ||
@@ -140,3 +143,3 @@ return; | ||
else { | ||
let moduleFactory = factoryCacheMap.get(moduleOrFactory); | ||
var moduleFactory = factoryCacheMap.get(moduleOrFactory); | ||
// If module factory is cached | ||
@@ -149,6 +152,6 @@ if (moduleFactory) { | ||
compiler.compileModuleAsync(moduleOrFactory) | ||
.then((factory) => { | ||
.then(function (factory) { | ||
factoryCacheMap.set(moduleOrFactory, factory); | ||
resolve(factory); | ||
}, (err => { | ||
}, (function (err) { | ||
reject(err); | ||
@@ -155,0 +158,0 @@ })); |
@@ -1,4 +0,6 @@ | ||
import { InjectionToken } from '@angular/core'; | ||
export const REQUEST = new InjectionToken('REQUEST'); | ||
export const ORIGIN_URL = new InjectionToken('ORIGIN_URL'); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var core_1 = require("@angular/core"); | ||
exports.REQUEST = new core_1.InjectionToken('REQUEST'); | ||
exports.ORIGIN_URL = new core_1.InjectionToken('ORIGIN_URL'); | ||
//# sourceMappingURL=tokens.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
30
243
34172