Pre-render your Single-Page Application.
npm install kasha!logo
s.robots.txt with sitemap directives. tag, tags, so search engine can know more about the page. You can use set-meta.sh
npm i -g kasha
`Docker:
`sh
docker pull kasha/kasha
`Configuration
See config.sample.jsRunning
$3
`sh
kasha server --config=/path/to/config.js
`Docker:
`sh
docker run -v /path/to/config.js:/dest/to/config.js kasha/kasha server --config=/dest/to/config.js
`$3
`sh
kasha worker --config=/path/to/config.jsasync worker
requests with 'callbackURL' parameter will be dispatched to async workers.
kasha worker --async --config=/path/to/config.js
`Docker:
`sh
docker run -v /path/to/config.js:/dest/to/config.js kasha/kasha worker [--async] --config=/dest/to/config.js
`Site Config
`js
db.sites.insert({
// The hostname of your site.
host: 'www.example.com', // In proxy mode, if the request doesn't contain 'X-Forwarded-Proto' or 'Forwarded:...proto=...' header,
// then use 'defaultProtocol'.
defaultProtocol: 'https',
// If your site use REST-style URLs, like /article/123, the query string isn't necessary to the page,
// you can remove the query string to improve the cache hit rate:
// keepQuery: false,
// You can also keep the required query parameter of some URLs
keepQuery: [
[
'/search', // the first element is the pathname of URL.
'type', // starting from the second element, specifies the query names you need to keep.
'keyword'
],
// another URL and its query names
['/product', 'id']
],
// You can use the '/render' API to crawl the hash-based Single-page application.
// For example, you can crawl https://www.example.com/app/#/home via
// /render?url=https%3A%2F%2Fwww.example.com%2Fapp%2F%23%2Fhome
// But if this site is not hash-based, you can remove the hash:
keepHash: false,
// Rewrites the request URL.
rewrites: [
// [from, to]
// If 'to' is an empty string, the request will be aborted.
// pattern syntax see https://github.com/jiangfengming/url-router#pattern
// route all requests to the entry point HTML file
['https://www.example.com/(.*)', 'https://static.example.com/index.html'],
// except robots.txt
['https://www.example.com/robots.txt', 'https://static.example.com/robots.txt'],
// or block it if you do not have one
// ['https://www.example.com/robots.txt', ''],
// block google analytics requests
['https://www.googletagmanager.com/(.*)', '']
],
// Excludes the pages that don't need pre-rendering.
excludes: [
'/your-account/(.*)',
'/your-orders/(.*)'
],
// But include these pages that matched the excludes pattern
includes: [
'your-account/signin'
],
// Specifies the User-Agent
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/73.0.3683.103 Safari/537.36',
// You can create profiles for different device types.
// A profile can override keepQuery, keepHash, rewrites, excludes, includes, userAgent.
profiles: {
desktop: {
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/73.0.3683.103 Safari/537.36',
rewrites: [
[
'https://www.example.com/(.*)',
'https://static.example.com/desktop/index.html'
]
]
},
mobile: {
userAgent: 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/73.0.3683.103 Mobile Safari/537.36',
rewrites: [
[
'https://www.example.com/(.*)',
'https://static.example.com/mobile/index.html'
]
]
}
},
// If profile param of the request isn't set, use this profile
defaultProfile: 'desktop'
})
`APIs
Please confirm apiHost has been set correctly.For example, if set
apiHost: '127.0.0.1:3000', then only requests from http(s)://127.0.0.1:3000/* can access the APIs,
All other domains are served in proxy mode.$3
Renders the page.#### Query string params:
url: The encoded URL of the webpage to render.profile: The profile to use.type: Set the response type. Defaults to json.
* html: Returns html with header Content-Type: text/html.
* json: Returns json with header Content-Type: application/json.
static: Returns html with header Content-Type: text/html, but stripped the