Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@types/connect-history-api-fallback
Advanced tools
TypeScript definitions for connect-history-api-fallback
@types/connect-history-api-fallback provides TypeScript type definitions for the connect-history-api-fallback middleware. This middleware is used in single-page applications (SPAs) to handle the fallback for HTML5 history API, ensuring that the application can handle deep links and refreshes properly by redirecting all non-API requests to the index.html file.
Basic Usage
This code demonstrates the basic usage of the connect-history-api-fallback middleware in an Express application. It sets up the middleware to handle fallback for HTML5 history API and serves static files from the 'public' directory.
const history = require('connect-history-api-fallback');
const express = require('express');
const app = express();
app.use(history());
app.use(express.static('public'));
app.listen(3000, () => {
console.log('Server running on port 3000');
});
Custom Options
This code demonstrates how to use the connect-history-api-fallback middleware with custom options. The 'index' option specifies the fallback file, and the 'verbose' option enables logging of the rewrite process.
const history = require('connect-history-api-fallback');
const express = require('express');
const app = express();
const options = {
index: '/index.html',
verbose: true
};
app.use(history(options));
app.use(express.static('public'));
app.listen(3000, () => {
console.log('Server running on port 3000');
});
serve-static is a middleware for serving static files in an Express application. While it does not provide HTML5 history API fallback functionality, it is often used in conjunction with connect-history-api-fallback to serve static files after handling the fallback.
express-history-api-fallback is another middleware that provides similar functionality to connect-history-api-fallback. It is specifically designed for use with Express and offers a similar API for handling HTML5 history API fallbacks.
npm install --save @types/connect-history-api-fallback
This package contains type definitions for connect-history-api-fallback (https://github.com/bripkens/connect-history-api-fallback#readme).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/connect-history-api-fallback.
/// <reference types="node" />
import { Url } from "url";
import * as core from "express-serve-static-core";
export = historyApiFallback;
declare function historyApiFallback(options?: historyApiFallback.Options): core.RequestHandler;
declare namespace historyApiFallback {
interface Options {
readonly disableDotRule?: true | undefined;
readonly htmlAcceptHeaders?: readonly string[] | undefined;
readonly index?: string | undefined;
readonly logger?: typeof console.log | undefined;
readonly rewrites?: readonly Rewrite[] | undefined;
readonly verbose?: boolean | undefined;
}
interface Context {
readonly match: RegExpMatchArray;
readonly parsedUrl: Url;
readonly request: core.Request;
}
type RewriteTo = (context: Context) => string;
interface Rewrite {
readonly from: RegExp;
readonly to: string | RegExp | RewriteTo;
}
}
These definitions were written by Douglas Duteil.
FAQs
TypeScript definitions for connect-history-api-fallback
The npm package @types/connect-history-api-fallback receives a total of 9,431,134 weekly downloads. As such, @types/connect-history-api-fallback popularity was classified as popular.
We found that @types/connect-history-api-fallback demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.