forked from ngxs/store
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(store): do not re-use the global
Store
instance between differe…
…nt apps (ngxs#1740)
- Loading branch information
Showing
22 changed files
with
679 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
integrations/hello-world-ng11-ivy/cypress/integration-ssr/issue-1646-wrong-ssr-state.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/// <reference types="cypress" /> | ||
|
||
describe('Select decorator returning state from the wrong store during SSR (https://github.com/ngxs/store/issues/1646)', () => { | ||
it('should make concurrent requests and app should render correctly for each request', async () => { | ||
const promises: Promise<string>[] = Array.from({ length: 100 }).map(() => | ||
fetch('/').then(res => res.text()) | ||
); | ||
|
||
const bodies = await Promise.all(promises); | ||
|
||
bodies.forEach(body => { | ||
expect(body).to.contain('Angular 11 (ivy) Integration Test'); | ||
expect(body).to.contain('Counter is 0'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import 'zone.js/dist/zone-node'; | ||
|
||
import { APP_BASE_HREF } from '@angular/common'; | ||
import { ngExpressEngine } from '@nguniversal/express-engine'; | ||
import { REQUEST, RESPONSE } from '@nguniversal/express-engine/tokens'; | ||
import * as express from 'express'; | ||
import { join } from 'path'; | ||
|
||
import { AppServerModule } from './src/main.server'; | ||
|
||
export function app() { | ||
const server = express(); | ||
const distFolder = join(process.cwd(), 'dist-integration'); | ||
|
||
server.engine( | ||
'html', | ||
ngExpressEngine({ | ||
bootstrap: AppServerModule | ||
}) as any | ||
); | ||
|
||
server.set('view engine', 'html'); | ||
server.set('views', distFolder); | ||
|
||
server.get( | ||
'*.*', | ||
express.static(distFolder, { | ||
maxAge: '1y' | ||
}) | ||
); | ||
|
||
server.get('*', (req, res) => { | ||
res.render('index', { | ||
req, | ||
providers: [ | ||
{ provide: APP_BASE_HREF, useValue: req.baseUrl }, | ||
{ provide: REQUEST, useValue: req }, | ||
{ provide: RESPONSE, useValue: res } | ||
] | ||
}); | ||
}); | ||
|
||
return server; | ||
} | ||
|
||
function run() { | ||
const port = process.env.PORT || 4200; | ||
|
||
const server = app(); | ||
server.listen(port, () => { | ||
console.log(`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 | ||
declare const __non_webpack_require__: NodeRequire; | ||
// eslint-disable-next-line | ||
const mainModule = __non_webpack_require__.main; | ||
const moduleFilename = (mainModule && mainModule.filename) || ''; | ||
if (moduleFilename === __filename || moduleFilename.includes('iisnode')) { | ||
run(); | ||
} | ||
|
||
export * from './src/main.server'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
integrations/hello-world-ng11-ivy/src/app/app.server.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { ServerModule } from '@angular/platform-server'; | ||
|
||
import { AppModule } from './app.module'; | ||
import { AppComponent } from './app.component'; | ||
|
||
@NgModule({ | ||
imports: [AppModule, ServerModule], | ||
bootstrap: [AppComponent] | ||
}) | ||
export class AppServerModule {} |
Oops, something went wrong.