Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function renderAsPath(routePath: string = '', outPath: string = '') {
// Resolve
let distBase = path.resolve(path.join(__dirname, 'dist'));
outPath = path.join(distBase, outPath);
let relativePath = path.relative(outPath, distBase);
// add a . to no relative path result because we prepend
// to a / for BASE_URL below.
if (relativePath === '') {
relativePath = '.';
}
let stableTime: number = -1;
let baseUrl = '/';
return gulp.src('./index.html')
.pipe(prerender({
directives: [Html],
// NOTE: It is assumed that this is not called until the zone is stable.
ngOnStable: () => {
return new Promise((resolve) => {
setTimeout(resolve, 500);
});
},
providers: [
provide(APP_BASE_HREF, {useValue: baseUrl}),
provide(BASE_URL, {useValue: relativePath + '/'}),
provide(REQUEST_URL, {useValue: `${baseUrl}${routePath}`}),
provide(UrlResolver, {useValue: new NodeUrlResolver}),
NODE_ROUTER_PROVIDERS,
NODE_HTTP_PROVIDERS,
],
preboot: false,
function renderAsPath(routePath: string = '', outPath: string = '') {
// Resolve
let distBase = path.resolve(path.join(__dirname, 'dist'));
outPath = path.join(distBase, outPath);
let relativePath = path.relative(outPath, distBase);
// add a . to no relative path result because we prepend
// to a / for BASE_URL below.
if (relativePath === '') {
relativePath = '.';
}
let baseUrl = '/';
return gulp.src('./index.html')
.pipe(prerender({
directives: [Html],
// TODO: This is a hack to wait for components to render because Universal
// does not patch fs and wait for my fs calls to complete.
ngOnStable: () => new Promise((resolve) => setTimeout(resolve, 500)),
platformProviders: [
// provide(APP_BASE_HREF, {useValue: baseUrl}),
provide(BASE_URL, {useValue: relativePath + '/'}),
provide(ORIGIN_URL, {useValue: '/'}),
provide(REQUEST_URL, {useValue: `${baseUrl}${routePath}`}),
provide(UrlResolver, {useValue: new NodeUrlResolver}),
NODE_ROUTER_PROVIDERS,
NODE_HTTP_PROVIDERS,
],
preboot: true,
async: true
}))
gulp.task('prerender', () => {
let baseUrl = '/';
let dirs:any[] = [App];
return gulp.src('./index.html')
.pipe(prerender({
directives: dirs,
providers: [
provide(APP_BASE_HREF, {useValue: baseUrl}),
provide(BASE_URL, {useValue: path.resolve(__dirname)}),
provide(REQUEST_URL, {useValue: path.resolve(__dirname)}),
provide(UrlResolver, {useValue: new NodeUrlResolver}),
DEMO_PROVIDERS,
NODE_ROUTER_PROVIDERS,
NODE_HTTP_PROVIDERS,
],
platformProviders: [MATERIAL_NODE_PROVIDERS],
preboot: false,
async: true
}))
.pipe(gulp.dest('dist'));
});
gulp.task('prerender', () => {
return gulp.src('./src/index.html')
.pipe(prerender({
directives: [ App, Title, ServerOnlyApp ],
providers: [
provide(APP_BASE_HREF, {useValue: '/'}),
provide(REQUEST_URL, {useValue: '/'}),
ROUTER_PROVIDERS,
NODE_LOCATION_PROVIDERS,
],
preboot: true
}))
.pipe(gulp.dest('dist'));
});