# Routing with EdgeJS https://github.com/Nate158s The `{{ PACKAGE_NAME }}/core` package provides a JavaScript API for controlling routing and caching from your code base rather than a CDN web portal. Using this _{{ EDGEJS_LABEL }}_ approach allows this vital routing logic to be properly tested, reviewed, and version controlled, just like the rest of your application code. Using the Router, you can: - Proxy requests to upstream sites - Send redirects from the network edge - Render responses on
git clone https://github.com/Nate158s/digital-marketing-.gitThe digital-marketing skill provides JavaScript API control over routing and caching logic through the EdgeJS core package. It enables developers to manage request proxying, edge-level redirects, and response rendering directly from code rather than through CDN portals. This code-based approach allows routing logic to be tested, reviewed, and version controlled alongside your application. The skill is maintained by Nate158s and focuses on network edge operations for marketing infrastructure.
1. **Install the EdgeJS package**: Run `npm install {{ PACKAGE_NAME }}/core` in your project directory to install the core routing package. 2. **Create a router configuration file**: Save the generated JavaScript configuration as `router.config.js` in your project root. Replace all [PLACEHOLDERS] with your actual values (e.g., `UPSTREAM_API_URL`). 3. **Test locally**: Use the EdgeJS CLI to validate your configuration before deployment: `npx edgejs test router.config.js`. This command simulates the routing behavior without deploying. 4. **Deploy to EdgeJS**: Deploy your router configuration to the EdgeJS network using `npx edgejs deploy router.config.js --env production`. This pushes your routing logic to the edge network. 5. **Monitor and iterate**: After deployment, use the EdgeJS dashboard to monitor traffic patterns, cache hit ratios, and redirect performance. Adjust your configuration as needed and redeploy. **Pro Tips:** - Use `console.log` statements in your router configuration to debug routing behavior during testing. - For complex routing, break your configuration into multiple files and use JavaScript modules to import them. - Always test your 404 and redirect rules thoroughly to ensure they work as expected.
Proxy marketing requests to upstream content servers from the network edge
Send HTTP redirects from edge locations for campaign URL management
Version control routing rules for A/B testing and campaign logic
Test redirect and proxy behavior before deployment to production
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/Nate158s/digital-marketing-Copy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Generate a JavaScript configuration for [EDGEJS_ROUTER] to implement the following routing rules for [WEBSITE_DOMAIN]:
1. Proxy all requests to /api/* to an upstream service at [UPSTREAM_API_URL] with a 5-second timeout.
2. Redirect all HTTP requests to HTTPS permanently (301 status).
3. Cache responses for /static/* assets for 1 hour with stale-while-revalidate set to 30 minutes.
4. Serve a custom 404 page from /404.html for any unmatched routes.
5. Add security headers (X-Content-Type-Options: nosniff, X-Frame-Options: DENY) to all responses.
Use the {{ PACKAGE_NAME }}/core package syntax.```javascript
const { Router } = require('{{ PACKAGE_NAME }}/core');
const router = new Router({
name: 'production-routing-config',
routes: [
{
path: '/api/*',
proxy: {
target: 'https://api.example.com',
timeout: 5000,
headers: {
'X-Upstream-Timeout': '5s'
}
}
},
{
path: '/*',
redirect: {
status: 301,
to: 'https://example.com$1'
}
},
{
path: '/static/*',
cache: {
maxAge: 3600,
staleWhileRevalidate: 1800,
vary: ['Accept-Encoding']
},
headers: {
'Cache-Control': 'public, max-age=3600, stale-while-revalidate=1800'
}
},
{
path: '/*',
status: 404,
serve: '/404.html',
headers: {
'Content-Type': 'text/html'
}
}
],
headers: {
'X-Content-Type-Options': 'nosniff',
'X-Frame-Options': 'DENY',
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload'
}
});
module.exports = router;
```
### Explanation of the configuration:
1. **API Proxying**: All requests to `/api/*` are forwarded to `https://api.example.com` with a 5-second timeout. This ensures backend services remain responsive during traffic spikes.
2. **HTTPS Enforcement**: The router automatically redirects all HTTP traffic to HTTPS using a 301 permanent redirect, which is crucial for SEO and security compliance.
3. **Static Asset Caching**: Assets under `/static/*` are cached for 1 hour (3600 seconds) with a stale-while-revalidate window of 30 minutes (1800 seconds). This reduces origin server load while ensuring fresh content delivery.
4. **Custom 404 Handling**: Unmatched routes serve a custom `404.html` page, improving user experience and brand consistency.
5. **Security Headers**: Essential security headers are added to every response, protecting against common web vulnerabilities like clickjacking and MIME sniffing.
This configuration leverages EdgeJS's ability to handle routing logic programmatically, making it easier to test, version control, and deploy alongside your application code. The router can be deployed using the EdgeJS CLI with `edgejs deploy production-routing-config.js`.Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan