Skip to content

Commit

Permalink
feat(daffio): revert to module bootstrap in server (#2728)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 committed Jan 25, 2024
1 parent 97e9203 commit 9b07f7d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
14 changes: 8 additions & 6 deletions apps/daffio/server/server.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@

// eslint-disable-next-line import/no-unassigned-import
import 'zone.js/node';

import { APP_BASE_HREF } from '@angular/common';
import { CommonEngine } from '@angular/ssr';
import * as express from 'express';
import { existsSync } from 'node:fs';
import { join } from 'node:path';
import bootstrap from './src/main.server';

import { AppServerModule } from '../src/main.server';

// The Express app is exported so that it can be used by serverless Functions.
export function app(): express.Express {
Expand All @@ -25,7 +26,7 @@ export function app(): express.Express {
// server.get('/api/**', (req, res) => { });
// Serve static files from /browser
server.get('*.*', express.static(distFolder, {
maxAge: '1y'
maxAge: '1y',
}));

// All regular routes use the Angular engine
Expand All @@ -34,12 +35,13 @@ export function app(): express.Express {

commonEngine
.render({
bootstrap,
bootstrap: AppServerModule,
documentFilePath: indexHtml,
url: `${protocol}://${headers.host}${originalUrl}`,
publicPath: distFolder,
providers: [
{ provide: APP_BASE_HREF, useValue: baseUrl },],
{ provide: APP_BASE_HREF, useValue: baseUrl },
],
})
.then((html) => res.send(html))
.catch((err) => next(err));
Expand Down Expand Up @@ -68,4 +70,4 @@ if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
run();
}

export default bootstrap;
export * from '../src/main.server';
2 changes: 1 addition & 1 deletion apps/daffio/serverless/webpack.serverless.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ module.exports = {
__dirname: false,
},
// this makes sure we include node_modules and other 3rd party libraries
externals: [/(node_modules|main\..*\.js)/]
externals: [/(node_modules|main\..*\.js|.*\.txt|.*\.map)/]
}
13 changes: 10 additions & 3 deletions apps/daffio/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { HttpClientModule } from '@angular/common/http';
import { NgModule } from '@angular/core';
import {
APP_ID,
NgModule,
} from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ServiceWorkerModule } from '@angular/service-worker';
Expand Down Expand Up @@ -29,7 +32,7 @@ import { environment } from '../environments/environment';

@NgModule({
imports: [
BrowserModule.withServerTransition({ appId: 'serverApp' }),
BrowserModule,
BrowserAnimationsModule,

StoreModule.forRoot({}),
Expand Down Expand Up @@ -57,7 +60,7 @@ import { environment } from '../environments/environment';
StoreDevtoolsModule.instrument({
maxAge: 25, // Retains last 25 states
logOnly: environment.production, // Restrict extension to log-only mode
connectInZone: true
connectInZone: true,
}),
TemplateModule,
ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production }),
Expand All @@ -70,6 +73,10 @@ import { environment } from '../environments/environment';
],
providers: [
DAFF_THEME_INITIALIZER,
{
provide: APP_ID,
useValue: 'serverApp',
},
],
})
export class AppModule {}

0 comments on commit 9b07f7d

Please sign in to comment.