本文整理汇总了TypeScript中angular2-express-engine.createEngine函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createEngine函数的具体用法?TypeScript createEngine怎么用?TypeScript createEngine使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createEngine函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createEngine
const engine = (filePath: string, data: ejs.Data, done: Function): Function => {
const angularEngine = createEngine({});
return angularEngine(filePath, data, (err, str) => {
done(err, ejs.render(str, {assetUrl: assetUrl}));
});
};
示例2: createEngine
*/
host: process.env.HOST || '0.0.0.0',
/**
* The port to bind the web server to
*/
// We have to Remove this for Webpack Heroku
// port: process.env.PORT,
/**
* Alternate method to add multiple template engine, for single view template use config.views.engine
*/
views: {
engines: {
'ng2.html': createEngine({
precompile: true,
ngModule: MainModule
})
},
// engines: {
// 'ng2.html': 'html'
// },
path: require('../treefrog.json').outDir
}
/**
* SSL options
* Cert and key or pfx to create HTTPS server
*/
/*
ssl: {
key: fs.readFileSync('path/to/private.key'),
示例3: enableProdMode
import * as path from 'path';
import * as express from 'express';
import { enableProdMode } from '@angular/core';
import { createEngine } from 'angular2-express-engine';
// Angular 2 Universal
enableProdMode();
import { main } from './main.node';
const app = express();
const ROOT = path.join(path.resolve(__dirname, '..'));
// Express View
app.engine('.html', createEngine({ main, time: true }));
app.set('views', __dirname);
app.set('view engine', 'html');
// Serve static files
app.use(express.static(ROOT, { index: false }));
app.get('/', function (req, res, next) {
res.render('index', { req, res });
});
// Server
app.listen(3000, () => {
console.log('Listening on: http://localhost:3000');
});
示例4: ConnectToDatabase
});
/*
* Connect to database
* Info: See database.ts to configure settings
*/
import { ConnectToDatabase } from './database';
ConnectToDatabase();
/*
* Configure Express.js rendering engine
*/
app.engine('.html', createEngine({}));
app.set('views', path.join(ROOT, '/public/views'));
app.set('view engine', 'html');
/*
* Configure Middleware
*/
app.use(cookieParser('Angular 2 Universal'));
app.use(bodyParser.json());
app.use(helmet());
/*
* Set directories to serve static assets from
*/
app.use(express.static(path.join(ROOT, 'public'), {index: false}));
app.use('/assets/js', express.static(path.join(ROOT, '/dist/client')));
示例5: enableProdMode
import * as path from 'path';
import * as express from 'express';
import { enableProdMode } from '@angular/core';
import { createEngine } from 'angular2-express-engine';
// Angular 2 Universal
enableProdMode();
import { MainModule } from './main.node';
const app = express();
const ROOT = path.join(path.resolve(__dirname, '..'));
// Express View
app.engine('.html', createEngine({ ngModule: MainModule, time: true }));
app.set('views', __dirname);
app.set('view engine', 'html');
// Serve static files
app.use(express.static(ROOT, { index: false }));
app.get('/data.json', function(req: any, res: any) {
console.log('req.headers.cookie', req.headers.cookie);
console.log('req.cookies', req.cookies);
var data = JSON.stringify({ data: true }, null, 2);
console.log('res', data);
res.status(200).send(data);
});
示例6: enableProdMode
// Routes
import { routes } from './server.routes';
// enable prod for faster renders
enableProdMode();
const app = express();
const ROOT = path.join(path.resolve(__dirname, '..'));
// Express View
app.engine('.html', createEngine({
ngModule: MainModule,
providers: [
// use only if you have shared state between users
// { provide: 'LRU', useFactory: () => new LRU(10) }
// stateless providers only since it's shared
]
}));
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname);
app.set('view engine', 'html');
app.set('json spaces', 2);
app.use(cookieParser('Angular 2 Universal'));
app.use(bodyParser.json());
app.use(compression());
app.use(morgan('dev'));
示例7: enableProdMode
// Routes
import { routes } from './server.routes';
// enable prod for faster renders
enableProdMode();
const app = express();
const ROOT = path.join(path.resolve(__dirname, '..'));
// Express View
app.engine('.html', createEngine({
precompile: false, // this needs to be false when using ngFactory
ngModule: MainModuleNgFactory,
providers: [
// use only if you have shared state between users
// { provide: 'LRU', useFactory: () => new LRU(10) }
// stateless providers only since it's shared
]
}));
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname);
app.set('view engine', 'html');
app.set('json spaces', 2);
app.use(cookieParser('Angular 2 Universal'));
app.use(bodyParser.json());
app.use(compression());
const accessLogStream = fs.createWriteStream(ROOT + '/morgan.log', {flags: 'a'})