Skip to content

Commit

Permalink
Proxy Plausible though the next server
Browse files Browse the repository at this point in the history
This configuration for next-plausible causes the next script and the
analytics endpoint to be proxied through the next app itself. The script
is also renamed (hopefully to avoid blocking).
  • Loading branch information
jonathansick committed Aug 21, 2024
1 parent 55ff9ab commit f032b76
Showing 1 changed file with 47 additions and 44 deletions.
91 changes: 47 additions & 44 deletions apps/squareone/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const Ajv = require('ajv').default;
const { withPlausibleProxy } = require('next-plausible');

const readYamlConfig = (configPath, schemaPath) => {
try {
Expand Down Expand Up @@ -42,48 +43,50 @@ const readServerYamlConfig = () => {
return data;
};

module.exports = (phase, { defaultConfig }) => {
const publicYamlConfig = readPublicYamlConfig();
const serverYamlConfig = readServerYamlConfig();
module.exports = withPlausibleProxy({ scriptName: 'dashing_rabbit' })(
({ phase, defaultConfig }) => {
const publicYamlConfig = readPublicYamlConfig();
const serverYamlConfig = readServerYamlConfig();

const config = {
...defaultConfig,
publicRuntimeConfig: { ...publicYamlConfig },
serverRuntimeConfig: { ...serverYamlConfig },
async rewrites() {
return [
// Mock Gafaelfawr (this is never triggered by a production ingress)
{
source: '/auth/api/v1/user-info',
destination: '/api/dev/user-info',
},
// Mock Times Square (this is never triggered by a production ingress)
{
source: '/times-square/api/v1/pages',
destination: '/api/dev/times-square/v1/pages',
},
{
source: '/times-square/api/v1/pages/:page/html',
destination: '/api/dev/times-square/v1/pages/:page/html',
},
{
source: '/times-square/api/v1/pages/:page/htmlstatus',
destination: '/api/dev/times-square/v1/pages/:page/htmlstatus',
},
{
source: '/times-square/api/v1/pages/:page',
destination: '/api/dev/times-square/v1/pages/:page',
},
{
source: '/times-square/api/v1/github',
destination: '/api/dev/times-square/v1/github',
},
{
source: '/times-square/api/v1/github/:tsSlug*',
destination: '/api/dev/times-square/v1/github/:tsSlug*',
},
];
},
};
return config;
};
const config = {
...defaultConfig,
publicRuntimeConfig: { ...publicYamlConfig },
serverRuntimeConfig: { ...serverYamlConfig },
async rewrites() {
return [
// Mock Gafaelfawr (this is never triggered by a production ingress)
{
source: '/auth/api/v1/user-info',
destination: '/api/dev/user-info',
},
// Mock Times Square (this is never triggered by a production ingress)
{
source: '/times-square/api/v1/pages',
destination: '/api/dev/times-square/v1/pages',
},
{
source: '/times-square/api/v1/pages/:page/html',
destination: '/api/dev/times-square/v1/pages/:page/html',
},
{
source: '/times-square/api/v1/pages/:page/htmlstatus',
destination: '/api/dev/times-square/v1/pages/:page/htmlstatus',
},
{
source: '/times-square/api/v1/pages/:page',
destination: '/api/dev/times-square/v1/pages/:page',
},
{
source: '/times-square/api/v1/github',
destination: '/api/dev/times-square/v1/github',
},
{
source: '/times-square/api/v1/github/:tsSlug*',
destination: '/api/dev/times-square/v1/github/:tsSlug*',
},
];
},
};
return config;
}
);

0 comments on commit f032b76

Please sign in to comment.