本文整理汇总了TypeScript中@nguniversal/express-engine.ngExpressEngine函数的典型用法代码示例。如果您正苦于以下问题:TypeScript ngExpressEngine函数的具体用法?TypeScript ngExpressEngine怎么用?TypeScript ngExpressEngine使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ngExpressEngine函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: ngExpressEngine
const bootstrap = () => {
app.engine('html', ngExpressEngine({
bootstrap: AppServerModule
}));
app.set('view engine', 'html');
app.set('views', './');
app.use('/', express.static('./', { index: false }));
app.get('*', (req, res) => {
res.render('index', {
req,
res
});
});
app.listen(port, () => {
console.log(`Listening at ${baseUrl}`);
});
};
示例2: enableProdMode
import { ServerAppModuleNgFactory } from './ngfactory/app/server-app.module.ngfactory';
import { ngExpressEngine } from '@nguniversal/express-engine';
import { ROUTES } from './routes';
import { enableProdMode } from '@angular/core';
enableProdMode();
const app = express();
app.use(compression());
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(awsServerlessExpressMiddleware.eventContext());
app.engine('html', ngExpressEngine({
bootstrap: ServerAppModuleNgFactory
}));
app.set('view engine', 'html');
app.set('views', 'src');
app.use('/', express.static('dist', { index: false }));
ROUTES.forEach((route) => {
app.get(route, (req, res) => {
res.render('../dist/index', { req, res });
});
});
// redirection from safari notification to given external page
app.get('/redirect/**', (req, res) => {
示例3: readFileSync
// Our index.html we'll use as our template
const template = readFileSync(join(DIST_FOLDER, 'browser', 'index.html')).toString();
// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/server/main.bundle');
// Express Engine
import { ngExpressEngine } from '@nguniversal/express-engine';
// Import module map for lazy loading
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
app.engine('html', ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
providers: [
provideModuleMap(LAZY_MODULE_MAP)
]
}));
app.set('view engine', 'html');
app.set('views', join(DIST_FOLDER, 'browser'));
/* - Example Express Rest API endpoints -
app.get('/api/**', (req, res) => { });
*/
// Server static files from /browser
app.get('*.*', express.static(join(DIST_FOLDER, 'browser'), {
maxAge: '1y'
}));
示例4: enableProdMode
import { ngExpressEngine, REQUEST } from '@nguniversal/express-engine';
import { enableProdMode } from '@angular/core';
import { USERAGENTTOKEN } from './app/windowRef';
enableProdMode();
export const app = express();
app.use(compression());
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(awsServerlessExpressMiddleware.eventContext());
app.engine('html', ngExpressEngine({
bootstrap: ServerAppModule,
providers: [
{provide: USERAGENTTOKEN, useValue: REQUEST }
]
}));
app.set('view engine', 'html');
app.set('views', 'dist');
app.use('/', express.static('dist', { index: false }));
app.get('/**', (req, res) => {
if (req.headers.host.indexOf('angular-universal-pwa.maciejtreder.com') > -1 && req.headers.host !== 'www.angular-universal-pwa.maciejtreder.com') {
res.writeHead (301, {Location: 'https://www.angular-universal-pwa.maciejtreder.com'});
res.end();
return;
}
res.render('index', {req, res});
示例5: require
/* tslint:disable */
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
/* tslint:enable */
import * as express from 'express';
import * as functions from 'firebase-functions';
import * as fs from 'fs';
import { ngExpressEngine } from '@nguniversal/express-engine';
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./app/main');
const engine = ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
providers: [
provideModuleMap(LAZY_MODULE_MAP)
]
});
const document: string = fs.readFileSync(__dirname + '/app/index.html', 'utf8').toString();
const app = express();
app.get('**', (req, res) => {
const url: string = req.path;
engine(url, {
req,
res,
url,
document,
bootstrap: AppServerModuleNgFactory,
providers: [
示例6: enableProdMode
import { enableProdMode } from '@angular/core';
// libs
import * as express from 'express';
import * as compression from 'compression';
import { ngExpressEngine } from '@nguniversal/express-engine';
// module
import { AppServerModule } from './app/app.server.module';
enableProdMode();
const server = express();
server.use(compression());
server.engine('html', ngExpressEngine({
bootstrap: AppServerModule
}));
server.set('view engine', 'html');
server.set('views', 'public');
server.use('/', express.static('public', {index: false}));
server.get('*', (req, res) => {
res.render('../public/index.html', {
req,
res
});
});
const PORT = process.env.PORT || 8000;
const HOST = process.env.BASE_URL || 'localhost';