本文整理匯總了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;
}