Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Angular] remove the server wrapper from angular sample app #522

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/angular/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"builder": "@angular-devkit/build-angular:server",
"options": {
"outputPath": "dist/server",
"main": "src/main.server.ts",
"main": "server.bundle.ts",
"tsConfig": "src/tsconfig.server.json"
},
"configurations": {
Expand Down
2 changes: 1 addition & 1 deletion samples/angular/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions samples/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@
"jss": "jss",
"start": "npm-run-all --serial bootstrap:disconnected --parallel start:angular start:proxy start:watch-components",
"start:connected": "scjss-verify-setup && npm-run-all --serial bootstrap:connected start:angular start:watch-components",
"build": "npm-run-all --serial bootstrap:connected --serial build:client build:server --serial build:server-wrapper",
"build": "npm-run-all --serial bootstrap:connected --serial build:client build:server",
"scaffold": "ng generate @sitecore-jss/sitecore-jss-angular-schematics:jss-component",
"start:angular": "ng serve -o --base-href=/ --source-map=false",
"start:proxy": "ts-node --project src/tsconfig.webpack-server.json scripts/disconnected-mode-proxy.ts",
"start:watch-components": "ts-node --project src/tsconfig.webpack-server.json scripts/generate-component-factory.ts --watch",
"build:client": "cross-env-shell ng build --prod --deploy-url $npm_package_config_sitecoreDistPath/browser/ --output-path=$npm_package_config_buildArtifactsPath/browser/",
"build:server": "cross-env-shell ng run JssAngularWeb:server:production --output-path=$npm_package_config_buildArtifactsPath/server --output-hashing=none --bundleDependencies true",
"build:server-wrapper": "cross-env-shell webpack --config webpack.server.config.js --progress --colors --output-path $npm_package_config_buildArtifactsPath",
"bootstrap:connected": "ts-node --project src/tsconfig.webpack-server.json scripts/bootstrap.ts",
"bootstrap:disconnected": "ts-node --project src/tsconfig.webpack-server.json scripts/bootstrap.ts --disconnected",
"graphql:update": "ts-node --project src/tsconfig.webpack-server.json ./scripts/update-graphql-fragment-data.ts"
Expand Down Expand Up @@ -128,7 +127,6 @@
"ts-loader": "~6.2.0",
"ts-node": "~8.4.1",
"typescript": "~3.9.7",
"webpack-cli": "~3.3.9",
"yaml-lint": "^1.2.4"
}
}
}
19 changes: 9 additions & 10 deletions samples/angular/server.bundle.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
// These are important and needed before anything else
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import { join } from 'path';
import { readFileSync } from 'fs';
import { join } from 'path';
import 'reflect-metadata';
import 'zone.js/dist/zone-node';
import { JssRouteBuilderService } from './src/app/routing/jss-route-builder.service';
import { environment } from './src/environments/environment';
import { AppServerModule, renderModule } from './src/main.server';

export * from './src/main.server';

const http = require('http');
const https = require('https');

// Our index.html we'll use as our template
const template = readFileSync(join(__dirname, 'browser', 'index.html')).toString();

// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const { AppServerModule, renderModule } = require('./dist/server/main');


// Setup Http/Https agents for keep-alive. Used in headless-proxy
const setUpDefaultAgents = (httpAgent, httpsAgent) => {
http.globalAgent = httpAgent;
https.globalAgent = httpsAgent;
};

// this is the function expected by the JSS View Engine for "integrated mode"
function renderView (callback, path, data, viewBag) {
function renderView(callback, path, data, viewBag) {
try {
/*
Data from server is double-encoded since MS JSS does not allow control
Expand Down Expand Up @@ -68,8 +67,8 @@ function renderView (callback, path, data, viewBag) {
{ provide: 'JSS_SERVER_VIEWBAG', useValue: state.viewBag },
]
})
.then(html => callback(null, { html }))
.catch(err => callback(err, null))
.then(html => callback(null, { html }))
.catch(err => callback(err, null))
} catch (err) {
// need to ensure the callback is always invoked no matter what
// or else SSR will hang
Expand Down
6 changes: 5 additions & 1 deletion samples/angular/src/tsconfig.server.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"lib": [
"esnext.asynciterable"
],
"files": [
"main.server.ts",
"../server.bundle.ts"
],
"exclude": [
"test.ts",
"**/*.spec.ts",
Expand All @@ -22,4 +26,4 @@
"angularCompilerOptions": {
"entryModule": "app/app.server.module#AppServerModule"
}
}
}
44 changes: 0 additions & 44 deletions samples/angular/webpack.server.config.js

This file was deleted.