All Projects → exequiel09 → fastify-angular-universal

exequiel09 / fastify-angular-universal

Licence: MIT license
Angular Universal integration to Fastify for rendering Angular apps on the server

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to fastify-angular-universal

fastify-file-upload
Fastify plugin for uploading files
Stars: ✭ 68 (+240%)
Mutual labels:  fastify, fastifyjs-plugin
ngx-metafrenzy
🏷️ Angular module for setting meta/link tags such as open graph, canonical, robots, and title
Stars: ✭ 19 (-5%)
Mutual labels:  server-side-rendering, angular-universal
node-ng-ssr-example
Simple Angular Server Side Rendering example
Stars: ✭ 15 (-25%)
Mutual labels:  server-side-rendering, angular-universal
fastify-jwt-authz
Verify authenticated user scope
Stars: ✭ 14 (-30%)
Mutual labels:  fastify, fastifyjs-plugin
fastify-vite
This plugin lets you load a Vite client application and set it up for Server-Side Rendering (SSR) with Fastify.
Stars: ✭ 497 (+2385%)
Mutual labels:  server-side-rendering, fastify
fastify-nodemailer
Fastify nodemailer plugin
Stars: ✭ 23 (+15%)
Mutual labels:  fastify, fastifyjs-plugin
mean-start-2
Full stack Angular + Nest + Universal.
Stars: ✭ 19 (-5%)
Mutual labels:  server-side-rendering, angular-universal
elegant-react-ssr
Server-side rendering with create-react-app, React Router v4, Helmet, Redux, and Thunk boilerplate, without ejecting CRA
Stars: ✭ 16 (-20%)
Mutual labels:  server-side-rendering
fastify-prisma
Basic Fastify app using Prisma as an ORM
Stars: ✭ 26 (+30%)
Mutual labels:  fastify
Modern-Web-App
React PWA with SSR and Code splitting
Stars: ✭ 45 (+125%)
Mutual labels:  server-side-rendering
fastify-session
session plugin for fastify
Stars: ✭ 93 (+365%)
Mutual labels:  fastify
fastify-etag
Automatically generate etags for HTTP responses, for Fastify
Stars: ✭ 61 (+205%)
Mutual labels:  fastify
choo-pwa
PWA with Choo
Stars: ✭ 18 (-10%)
Mutual labels:  fastify
react-coat-ssr-demo
Demo with Typescript + React + Redux for server-side-rendering (SSR)
Stars: ✭ 100 (+400%)
Mutual labels:  server-side-rendering
medellinjs
MedellinJS
Stars: ✭ 61 (+205%)
Mutual labels:  server-side-rendering
isomorphic-react-redux-saga-ssr
Isomorphic, React, Redux, Saga, Server Side rendering, Hot Module Reloading, Ducks, Code Splitting
Stars: ✭ 19 (-5%)
Mutual labels:  server-side-rendering
kodepos
📮 Indonesian postal code search API by place name, village or city.
Stars: ✭ 32 (+60%)
Mutual labels:  fastify
fastify-cors
Fastify CORS
Stars: ✭ 212 (+960%)
Mutual labels:  fastify
webpack-isomorphic-compiler
A compiler that makes your life easier if you are building isomorphic webpack powered apps, that is, single page applications with server-side rendering
Stars: ✭ 16 (-20%)
Mutual labels:  server-side-rendering
Converto
Installing Kali linux on Vps Server
Stars: ✭ 100 (+400%)
Mutual labels:  server-side-rendering

fastify-angular-universal

Master - Build Status Master - Build Status LICENSE

Angular server-side rendering support for Fastify using Angular Universal.

Install

npm install --save fastify-angular-universal

Usage

Add it to you project with register and pass the required options.

Follow the tutorial on how to perform SSR in Angular with Angular CLI here ONLY UNTIL step 3.

For the steps 4 and onwards use the following server.ts or check out the server.ts in the test-app directory

// These are important and needed before anything else
import 'zone.js/dist/zone-node';
import 'reflect-metadata';

import { join } from 'path';
import { readFileSync } from 'fs';

import { enableProdMode } from '@angular/core';
import * as fastify from 'fastify';

// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/<your-project-name-here>-server/main');
const { provideModuleMap } = require('@nguniversal/module-map-ngfactory-loader');

// Faster server renders w/ Prod mode (dev mode never needed)
enableProdMode();

const PORT = process.env.PORT || 3000;
const DIST_FOLDER = join(process.cwd(), 'dist');

// Our index.html we'll use as our template
const template = readFileSync(join(DIST_FOLDER, '<your-project-name-here>', 'index.html')).toString();

const app = fastify();

app.register(require('fastify-static'), {
  root: join(DIST_FOLDER, '<your-project-name-here>'),
  prefix: '/static/'
});

// register the fastify-angular-universal to your application together with the required options
app.register(require('fastify-angular-universal'), {
  serverModule: AppServerModuleNgFactory,
  document: template,
  extraProviders: [
    provideModuleMap(LAZY_MODULE_MAP)
  ]
});

// Declare a route
app.get('/*', function (request, reply) {
  // NOTE: you can also pass the options for the fastify-angular-universal fastify plugin 
  //       as second parameter to the `.renderNg()` function.
  // 
  //       Example: `reply.renderNg(url, options)`
  (reply as any).renderNg(request.req.url);
});

// Run the server!
app.listen(PORT, function (err) {
  if (err) {
    throw err;
  }

  console.log(`server listening on ${app.server.address().port}`);
});

Options

This plugin allow you to specify options:

  • serverModule to specify the NgModuleFactory to be used in rendering an Angular app in the server
  • document to specify the template where the Angular app will be rendered
  • extraProviders to specify additional providers to be used by the Angular app. (optional)

License

MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].