SSR snippets outdated?
Closed this issue · 1 comments
omerman commented
Which @ngneat/query-* package(s) are the source of the bug?
query
Is this a regression?
No
Description
I couldn't understand how to piece together the SSR snipets.
it seems outdated.
Help?
if it helps here is my server.ts code.
import 'zone.js/dist/zone-node';
import { APP_BASE_HREF } from '@angular/common';
import { ngExpressEngine } from '@nguniversal/express-engine';
import * as express from 'express';
import * as compression from 'compression';
import { existsSync } from 'fs';
import { join } from '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();
server.use(compression());
const distFolder = join(process.cwd(), 'dist/apps/nx-ng-test-project/browser');
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',
ngExpressEngine({
bootstrap,
})
);
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',
})
);
// All regular routes use the Universal engine
server.get('*', (req, res) => {
res.render(indexHtml, {
req,
providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }],
});
});
return server;
}
function run(): void {
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}`);
});
}
// 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.
declare const __non_webpack_require__: NodeRequire;
const mainModule = __non_webpack_require__.main;
const moduleFilename = (mainModule && mainModule.filename) || '';
if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
run();
}
export default bootstrap;
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
./node_modules/xhr2/lib/xhr2.js:281
throw new NetworkError(`Unsupported protocol ${this._url.protocol}`);
^
Error
at send (./node_modules/xhr2/lib/xhr2.js:281:19)
at Observable._subscribe (/Users/omerprizner/dev/nx-projects/dist/apps/nx-ng-test-project/server/vendor.js:73345:13)
at Observable._trySubscribe (/Users/omerprizner/dev/nx-projects/dist/apps/nx-ng-test-project/server/vendor.js:29130:19)
at /Users/omerprizner/dev/nx-projects/dist/apps/nx-ng-test-project/server/vendor.js:29124:115
at Object.errorContext (/Users/omerprizner/dev/nx-projects/dist/apps/nx-ng-test-project/server/vendor.js:38800:5)
at Observable.subscribe (/Users/omerprizner/dev/nx-projects/dist/apps/nx-ng-test-project/server/vendor.js:29120:20)
at /Users/omerprizner/dev/nx-projects/dist/apps/nx-ng-test-project/server/vendor.js:35662:57
at OperatorSubscriber._this._next (/Users/omerprizner/dev/nx-projects/dist/apps/nx-ng-test-project/server/vendor.js:31916:9)
at OperatorSubscriber.Subscriber.next (/Users/omerprizner/dev/nx-projects/dist/apps/nx-ng-test-project/server/vendor.js:29628:12)
at /Users/omerprizner/dev/nx-projects/dist/apps/nx-ng-test-project/server/vendor.js:31255:20
### Please provide the environment you discovered this bug in
```true
NX + Angular universal
Anything else?
Help me <3
Do you want to create a pull request?
Yes
NetanelBasal commented
You're welcome to create a PR :)