Skip to content

Commit 75c5a67

Browse files
committed
Initial commit
1 parent 3e62aed commit 75c5a67

26 files changed

+508
-549
lines changed

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: npm run start:heroku

angular.json

+53-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"build": {
1818
"builder": "@angular-devkit/build-angular:browser",
1919
"options": {
20-
"outputPath": "dist/carsome-coding",
20+
"outputPath": "dist/carsome-coding/browser",
2121
"index": "src/index.html",
2222
"main": "src/main.ts",
2323
"polyfills": "src/polyfills.ts",
@@ -28,6 +28,7 @@
2828
"src/assets"
2929
],
3030
"styles": [
31+
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
3132
"src/styles.scss"
3233
],
3334
"scripts": []
@@ -92,6 +93,7 @@
9293
"src/assets"
9394
],
9495
"styles": [
96+
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
9597
"src/styles.scss"
9698
],
9799
"scripts": []
@@ -121,8 +123,56 @@
121123
"devServerTarget": "carsome-coding:serve:production"
122124
}
123125
}
126+
},
127+
"server": {
128+
"builder": "@angular-devkit/build-angular:server",
129+
"options": {
130+
"outputPath": "dist/carsome-coding/server",
131+
"main": "server.ts",
132+
"tsConfig": "tsconfig.server.json"
133+
},
134+
"configurations": {
135+
"production": {
136+
"outputHashing": "media",
137+
"fileReplacements": [
138+
{
139+
"replace": "src/environments/environment.ts",
140+
"with": "src/environments/environment.prod.ts"
141+
}
142+
],
143+
"sourceMap": false,
144+
"optimization": true
145+
}
146+
}
147+
},
148+
"serve-ssr": {
149+
"builder": "@nguniversal/builders:ssr-dev-server",
150+
"options": {
151+
"browserTarget": "carsome-coding:build",
152+
"serverTarget": "carsome-coding:server"
153+
},
154+
"configurations": {
155+
"production": {
156+
"browserTarget": "carsome-coding:build:production",
157+
"serverTarget": "carsome-coding:server:production"
158+
}
159+
}
160+
},
161+
"prerender": {
162+
"builder": "@nguniversal/builders:prerender",
163+
"options": {
164+
"browserTarget": "carsome-coding:build:production",
165+
"serverTarget": "carsome-coding:server:production",
166+
"routes": [
167+
"/"
168+
]
169+
},
170+
"configurations": {
171+
"production": {}
172+
}
124173
}
125174
}
126-
}},
175+
}
176+
},
127177
"defaultProject": "carsome-coding"
128-
}
178+
}

package.json

+23-3
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,49 @@
77
"build": "ng build",
88
"test": "ng test",
99
"lint": "ng lint",
10-
"e2e": "ng e2e"
10+
"e2e": "ng e2e",
11+
"dev:ssr": "ng run carsome-coding:serve-ssr",
12+
"serve:ssr": "node dist/carsome-coding/server/main.js",
13+
"build:ssr": "ng build --prod && ng run carsome-coding:server:production",
14+
"prerender": "ng run carsome-coding:prerender",
15+
"start:heroku": "node dist/server",
16+
"postinstall": "npm run build:ssr"
1117
},
1218
"private": true,
1319
"dependencies": {
1420
"@angular/animations": "~9.1.11",
21+
"@angular/cdk": "^9.2.4",
1522
"@angular/common": "~9.1.11",
1623
"@angular/compiler": "~9.1.11",
1724
"@angular/core": "~9.1.11",
1825
"@angular/forms": "~9.1.11",
26+
"@angular/localize": "~9.1.11",
27+
"@angular/material": "^9.2.4",
1928
"@angular/platform-browser": "~9.1.11",
2029
"@angular/platform-browser-dynamic": "~9.1.11",
30+
"@angular/platform-server": "~9.1.11",
2131
"@angular/router": "~9.1.11",
32+
"@ng-bootstrap/ng-bootstrap": "^6.1.0",
33+
"@nguniversal/express-engine": "^9.1.1",
34+
"bootstrap": "^4.4.0",
35+
"date-fns": "^2.14.0",
36+
"dotenv": "^8.2.0",
37+
"express": "^4.15.2",
2238
"rxjs": "~6.5.4",
2339
"tslib": "^1.10.0",
2440
"zone.js": "~0.10.2"
2541
},
2642
"devDependencies": {
27-
"@angular-devkit/build-angular": "~0.901.8",
43+
"@angular-builders/custom-webpack": "^9.1.0",
44+
"@angular-builders/dev-server": "^7.3.1",
45+
"@angular-devkit/build-angular": "^0.901.9",
2846
"@angular/cli": "~9.1.8",
2947
"@angular/compiler-cli": "~9.1.11",
30-
"@types/node": "^12.11.1",
48+
"@nguniversal/builders": "^9.1.1",
49+
"@types/express": "^4.17.0",
3150
"@types/jasmine": "~3.5.0",
3251
"@types/jasminewd2": "~2.0.3",
52+
"@types/node": "^12.11.1",
3353
"codelyzer": "^5.1.2",
3454
"jasmine-core": "~3.5.0",
3555
"jasmine-spec-reporter": "~4.2.1",

server.ts

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import 'zone.js/dist/zone-node';
2+
3+
import { ngExpressEngine } from '@nguniversal/express-engine';
4+
import * as express from 'express';
5+
import { join } from 'path';
6+
7+
import { AppServerModule } from './src/main.server';
8+
import { APP_BASE_HREF } from '@angular/common';
9+
import { existsSync } from 'fs';
10+
11+
// The Express app is exported so that it can be used by serverless Functions.
12+
export function app() {
13+
const server = express();
14+
const distFolder = join(process.cwd(), 'dist/carsome-coding/browser');
15+
const indexHtml = existsSync(join(distFolder, 'index.original.html')) ? 'index.original.html' : 'index';
16+
17+
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
18+
server.engine('html', ngExpressEngine({
19+
bootstrap: AppServerModule,
20+
}));
21+
22+
server.set('view engine', 'html');
23+
server.set('views', distFolder);
24+
25+
// Example Express Rest API endpoints
26+
// server.get('/api/**', (req, res) => { });
27+
// Serve static files from /browser
28+
server.get('*.*', express.static(distFolder, {
29+
maxAge: '1y'
30+
}));
31+
32+
// All regular routes use the Universal engine
33+
server.get('*', (req, res) => {
34+
res.render(indexHtml, { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }] });
35+
});
36+
37+
return server;
38+
}
39+
40+
function run() {
41+
const port = process.env.PORT || 4000;
42+
43+
// Start up the Node server
44+
const server = app();
45+
server.listen(port, () => {
46+
console.log(`Node Express server listening on http://localhost:${port}`);
47+
});
48+
}
49+
50+
// Webpack will replace 'require' with '__webpack_require__'
51+
// '__non_webpack_require__' is a proxy to Node 'require'
52+
// The below code is to ensure that the server is run only when not requiring the bundle.
53+
declare const __non_webpack_require__: NodeRequire;
54+
const mainModule = __non_webpack_require__.main;
55+
const moduleFilename = mainModule && mainModule.filename || '';
56+
if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
57+
run();
58+
}
59+
60+
export * from './src/main.server';

src/app/app-routing.module.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import { NgModule } from '@angular/core';
22
import { Routes, RouterModule } from '@angular/router';
3+
import { AppointmentMainComponent } from './components/appointment-main/appointment-main.component';
34

45

5-
const routes: Routes = [];
6+
const routes: Routes = [
7+
{path: '', component: AppointmentMainComponent}
8+
];
69

710
@NgModule({
8-
imports: [RouterModule.forRoot(routes)],
11+
imports: [RouterModule.forRoot(routes, {
12+
initialNavigation: 'enabled'
13+
})],
914
exports: [RouterModule]
1015
})
1116
export class AppRoutingModule { }

0 commit comments

Comments
 (0)