How to host your site as a sub-directory?
Under “Domains” in Bullet dashboard, you can find “Href Prefix” where you can add your sub-directory, ex. /blog or /help.
After adding that, you have to set a reverse proxy to your primary domain and the sub-directory. You can use cloudflare workers for reverse proxying, or use something like nginx server for reverse proxying.
1. Cloudflare workers
Step-1: Create a new Cloudflare worker, and add the below code. Make appropriate changes in the third and fifth lines of the below code.
addEventListener('fetch', (event) => { // Add your bullet subdomain below. Avoid trailing slash const bulletUrl = new URL(`https://{{bullet-subdomain}}-bullet.pages.dev`) // Add sub-directory path where you want to see your bullet site in the next line. Avoid trailing slash/ const subdirectory = "/blog" const requestUrl = new URL(event.request.url) const pathname = requestUrl.pathname if (pathname.startsWith(`${subdirectory}/`) || pathname === subdirectory) { event.passThroughOnException() event.respondWith( fetch(`${bulletUrl.origin}${pathname.replace(subdirectory, "")}`, event.request), ) } else { event.respondWith(fetch(event.request)) } })
Step-2: After creating the worker and deploying, you will have to add the Worker Route, and set the path to
https://example.com/blog*
2. Nginx
Add this snippet under your
location /blog/ { proxy_pass https://{{bullet-subdomain}}-bullet.pages.dev/; }
3. Next.js
// next.config.js
/** @type {import('next').NextConfig} */
const config = {
rewrites() {
const bulletUrl = new URL(
`https://{{bullet-subdomain}}-bullet.pages.dev`,
).origin
return [
{
source: '/blog',
destination: `${bulletUrl}/blog`,
},
{
source: '/blog/:path*',
destination: `${bulletUrl}/blog/:path*`,
},
]
},
}
module.exports = config
Feel free to reach out to support if you have any issues.