本文整理汇总了TypeScript中connect-history-api-fallback类的典型用法代码示例。如果您正苦于以下问题:TypeScript connect-history-api-fallback类的具体用法?TypeScript connect-history-api-fallback怎么用?TypeScript connect-history-api-fallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了connect-history-api-fallback类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: express
import * as historyApiFallback from 'connect-history-api-fallback';
import * as express from "express";
const app = express();
app.use(historyApiFallback());
historyApiFallback({
verbose: true
});
historyApiFallback({
logger: console.log.bind(console)
});
historyApiFallback({
rewrites: [
{ from: /\/soccer/, to: '/soccer.html' }
]
});
historyApiFallback({
index: 'default.html'
});
historyApiFallback({
htmlAcceptHeaders: ['text/html', 'application/xhtml+xml']
});
historyApiFallback({
rewrites: [
示例2: init
/**
* This function initiates the server.
*/
function init(){
bs.init({
server : {
baseDir : './dist',
routes: {
"/node_modules": "node_modules"
}
},
middleware: [historyApiFallBack()]
});
}
示例3: serverDev
/**
* This function initialises the server in development mode.
*/
function serverDev() {
bs.init({
server: {
baseDir: DEV_PATH + '/',
routes: {
"/node_modules": "node_modules"
}
},
injectChanges: true,
middleware: [historyApiFallback()],
});
}
示例4: serverProd
/**
* This function initialises the server in production mode.
*/
function serverProd() {
bs.init({
server: {
baseDir: PROD_PATH + '/',
routes: {
"/node_modules": "node_modules"
}
},
middleware: [historyApiFallback(), compress()],
ghostMode: false,
ui: false,
notify: false,
port: process.env.PORT || 3000
});
}
示例5:
gulp.task('serve', () => {
browserSync.init({
notify: false,
server: {
baseDir: [DIR_TMP, DIR_SRC],
middleware: [historyApiFallback()],
routes: {
'/bower_components': 'bower_components',
'/node_modules': 'node_modules'
}
}
});
gulp.watch(`${DIR_SRC}/**/*.ts`, ['ts-watch']);
gulp.watch(`${DIR_SRC}/**/*.{css,html}`, null).on('change', browserSync.reload);
});
示例6: createServer
export function createServer(options: ServerOptions): JspmHmrServer {
// APP
const app = express();
// Apply gzip compression
app.use(compress());
// TODO: CORS
// const headers = {
// 'Access-Control-Allow-Origin': '*',
// 'Access-Control-Allow-Credentials': 'true',
// };
// Apply Proxy middleware
if (options.proxy) {
const proxyTarget = options.proxy;
const proxyRoute = options.proxyRoute || '*';
const proxyServer = httpProxy.createProxyServer();
app.use(proxyRoute, (req, res) => {
req.url = `${req.originalUrl}`;
proxyServer.web(req, res, { target: proxyTarget });
proxyServer.on('error', (err: Error) => {
console.log('Proxy Server Error: ', err.message);
});
});
}
// Apply Fallback middleware to rewrite route requests
// and serve /index.html for SPA Applications
if (options.fallback) {
const fallback = options.fallback === true ? '/index.html' : options.fallback;
console.log('history api fallback active', fallback);
app.use(historyApiFallback({
index: fallback, verbose: !!options.verbose,
}));
}
// Cache config
const cache = options.cache && options.cache * 1000 || -1;
// Server static files with cache headers
const staticRoot = options.path || '.';
console.log(`static files served from ${path.resolve(staticRoot)}`);
app.use(express.static(staticRoot, { maxAge: cache }));
// Creating NodeJS Server Instance
let serverInstance;
if (options.ssl) {
const key = options.key || Config.KEY_PATH;
const cert = options.cert || Config.CERT_PATH;
const sslOptions = (key && cert) && {
key: fs.readFileSync(key),
cert: fs.readFileSync(cert),
};
serverInstance = https.createServer(sslOptions, app);
} else {
serverInstance = http.createServer(app);
}
// Creating Chokidar Socket.io Server
if (!options.disableHmr) {
const chokidarOptions = {
...{ quiet: false, path: options.path },
app: serverInstance,
};
chokidar(chokidarOptions);
}
return serverInstance;
}