Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Nov 5, 2023
1 parent 82631a3 commit 49cc692
Show file tree
Hide file tree
Showing 10 changed files with 4,624 additions and 11,380 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: taiga-family/ci/actions/deploy/[email protected]
with:
token: ${{ secrets.TAIGA_FAMILY_BOT_PAT }}
folder: dist/demo/browser
folder: dist/demo

concurrency:
group: deploy-${{ github.head_ref }}
Expand Down
39 changes: 22 additions & 17 deletions apps/demo/server.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
import 'zone.js/node';

import {existsSync} from 'node:fs';
import {join} from 'node:path';

import {APP_BASE_HREF} from '@angular/common';
import {ngExpressEngine} from '@nguniversal/express-engine';
import express from 'express';
import {existsSync} from 'node:fs';
import {join} from 'node:path';

import bootstrap from './src/main.server';

// The Express app is exported so that it can be used by serverless Functions.
export function app(): express.Express {
const server = express();
const distFolder = join(process.cwd(), 'dist/demo');
const indexHtml = existsSync(join(distFolder, 'index.original.html'))
? 'index.original.html'
: 'index';
const distFolder = join(process.cwd(), `dist/demo`);
const indexHtml = existsSync(join(distFolder, `index.original.html`))
? `index.original.html`
: `index`;

// Our Universal express-engine (found @ https://github.com/angular/universal/tree/main/modules/express-engine)
server.engine(
'html',
`html`,
ngExpressEngine({
bootstrap,
}),
);

server.set('view engine', 'html');
server.set('views', distFolder);
server.set(`view engine`, `html`);
server.set(`views`, distFolder);

// Example Express Rest API endpoints
// server.get('/api/**', (req, res) => { });

// Serve static files from /browser
server.get(
'*.*',
`*.*`,
express.static(distFolder, {
maxAge: '1y',
maxAge: `1y`,
}),
);

// All regular routes use the Universal engine
server.get('*', (req, res) => {
server.get(`*`, (req, res) => {
res.render(indexHtml, {
req,
providers: [{provide: APP_BASE_HREF, useValue: req.baseUrl}],
Expand All @@ -49,22 +51,25 @@ export function app(): express.Express {
}

function run(): void {
const port = process.env['PORT'] || 4000;
const port = process.env[`PORT`] || 4000;

// Start up the Node server
const server = app();

server.listen(port, () => {
console.log(`Node Express server listening on http://localhost:${port}`);
console.info(`Node Express server listening on http://localhost:${port}`);
});
}

// Webpack will replace 'require' with '__webpack_require__'
// '__non_webpack_require__' is a proxy to Node 'require'
// The below code is to ensure that the server is run only when not requiring the bundle.
// eslint-disable-next-line @typescript-eslint/naming-convention
declare const __non_webpack_require__: NodeRequire;
const mainModule = __non_webpack_require__.main;
const moduleFilename = (mainModule && mainModule.filename) || '';
if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
const mainModule = __non_webpack_require__?.main;
const moduleFilename = mainModule?.filename ?? ``;

if (moduleFilename === __filename || moduleFilename.includes(`iisnode`)) {
run();
}

Expand Down
3 changes: 2 additions & 1 deletion apps/demo/src/app/app.config.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/

import {mergeApplicationConfig, ApplicationConfig} from '@angular/core';
import {ApplicationConfig, mergeApplicationConfig} from '@angular/core';
import {provideServerRendering} from '@angular/platform-server';

import {appConfig} from './app.config';

const serverConfig: ApplicationConfig = {
Expand Down
3 changes: 2 additions & 1 deletion apps/demo/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import {
BrowserAnimationsModule,
provideAnimations,
} from '@angular/platform-browser/animations';
import {provideRouter} from '@angular/router';
import {TuiRootModule} from '@taiga-ui/core';

import {routes} from './app.routes';
import {provideRouter} from '@angular/router';

export const appConfig: ApplicationConfig = {
providers: [
Expand Down
4 changes: 2 additions & 2 deletions apps/demo/src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Routes} from '@angular/router';

export const routes: Routes = [
{
path: '',
loadComponent: async () => (await import('./home/home.component')).HomeComponent,
path: ``,
loadComponent: async () => (await import(`./home/home.component`)).HomeComponent,
},
];
67 changes: 34 additions & 33 deletions apps/demo/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,47 @@ import {ChangeDetectionStrategy, Component} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {TuiDay} from '@taiga-ui/cdk';
import {
TuiButtonModule,
TuiCalendarModule,
TuiHintModule,
TuiTextfieldControllerModule,
TuiButtonModule,
TuiCalendarModule,
TuiHintModule,
TuiTextfieldControllerModule,
} from '@taiga-ui/core';
import {
TuiCheckboxLabeledModule,
TuiInputDateModule,
TuiInputTagModule, TuiSliderModule,
TuiToggleModule,
TuiCheckboxLabeledModule,
TuiInputDateModule,
TuiInputTagModule,
TuiSliderModule,
TuiToggleModule,
} from '@taiga-ui/kit';
import {EventPluginsModule} from '@tinkoff/ng-event-plugins';

@Component({
standalone: true,
selector: 'home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.less'],
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [
CommonModule,
FormsModule,
EventPluginsModule,
TuiInputTagModule,
TuiToggleModule,
TuiCalendarModule,
TuiTextfieldControllerModule,
TuiInputDateModule,
TuiCheckboxLabeledModule,
TuiButtonModule,
TuiHintModule,
TuiSliderModule,
],
standalone: true,
selector: 'home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.less'],
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [
CommonModule,
FormsModule,
EventPluginsModule,
TuiInputTagModule,
TuiToggleModule,
TuiCalendarModule,
TuiTextfieldControllerModule,
TuiInputDateModule,
TuiCheckboxLabeledModule,
TuiButtonModule,
TuiHintModule,
TuiSliderModule,
],
})
export class HomeComponent {
readonly labels = ['New', 'Read', 'Archived', 'Junk'];
tags = ['Angular', 'Open source'];
date: TuiDay | null = null;
readonly labels = ['New', 'Read', 'Archived', 'Junk'];
tags = ['Angular', 'Open source'];
date: TuiDay | null = null;

onDay(date: TuiDay): void {
this.date = date;
}
onDay(date: TuiDay): void {
this.date = date;
}
}
13 changes: 4 additions & 9 deletions apps/demo/src/main.server.ts
Original file line number Diff line number Diff line change
@@ -1,15 +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
*/

import {ApplicationRef} from '@angular/core';
import {bootstrapApplication} from '@angular/platform-browser';

import {AppComponent} from './app/app.component';
import {config} from './app/app.config.server';

const bootstrap = () => bootstrapApplication(AppComponent, config);
const bootstrap = async (): Promise<ApplicationRef> =>
bootstrapApplication(AppComponent, config);

export default bootstrap;
3 changes: 2 additions & 1 deletion apps/demo/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {bootstrapApplication} from '@angular/platform-browser';
import {appConfig} from './app/app.config';

import {AppComponent} from './app/app.component';
import {appConfig} from './app/app.config';

bootstrapApplication(AppComponent, appConfig).catch(err => console.error(err));
Loading

0 comments on commit 49cc692

Please sign in to comment.