Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
A few updates
Browse files Browse the repository at this point in the history
* Adding Google Analytics with Anonymous IP
* Adding event tracking so we can track most searched terms
* Fixed environmental variables for public site
* Added support to run server on different ports
* Updated search result scores to make deprecated items show up last
* Added CORS support for calling API from other websites
  • Loading branch information
Peter Schmalfeldt committed Nov 5, 2023
1 parent 7a0fb31 commit 58e861d
Show file tree
Hide file tree
Showing 16 changed files with 2,714 additions and 87 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
SELECTED_VERSION="23.9"
SITE_URL="https://sfccdocs.com"
NEXT_PUBLIC_SITE_URL="https://sfccdocs.com"
NEXT_PUBLIC_GOOGLE_ANALYTICS="G-G1ER54K5N0"
PORT=3000
10 changes: 10 additions & 0 deletions forever/dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"uid": "development",
"append": true,
"watch": true,
"script": "server.cjs",
"sourceDir": "./",
"logFile": "web-dev.log",
"outFile": "out-dev.log",
"errFile": "err-dev.log"
}
10 changes: 10 additions & 0 deletions forever/loc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"uid": "local",
"append": true,
"watch": true,
"script": "server.cjs",
"sourceDir": "./",
"logFile": "web-loc.log",
"outFile": "out-loc.log",
"errFile": "err-loc.log"
}
10 changes: 10 additions & 0 deletions forever/prd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"uid": "production",
"append": true,
"watch": true,
"script": "server.cjs",
"sourceDir": "./",
"logFile": "web-prd.log",
"outFile": "out-prd.log",
"errFile": "err-prd.log"
}
2 changes: 1 addition & 1 deletion next-sitemap.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dotenv/config'

/** @type {import('next-sitemap').IConfig} */
export default {
siteUrl: process.env.SITE_URL || 'https://sfccdocs.com',
siteUrl: process.env.NEXT_PUBLIC_SITE_URL || 'https://sfccdocs.com',
generateRobotsTxt: true,
sitemapSize: 1000,
changefreq: 'weekly',
Expand Down
20 changes: 19 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ import nextPWA from 'next-pwa'
import runtimeCaching from 'next-pwa/cache.js'
import withSearch from './src/markdoc/search.mjs'

const getCorsHeaders = () => {
const headers = {}

headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Credentials'] = 'true'
headers['Access-Control-Allow-Methods'] = 'GET,OPTIONS,PATCH,DELETE,POST,PUT'
headers['Access-Control-Allow-Headers'] = 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, Authorization'

return Object.entries(headers).map(([key, value]) => ({ key, value }))
}

const withPWA = nextPWA({
dest: 'public',
runtimeCaching,
Expand All @@ -14,11 +25,18 @@ const nextConfig = {
trailingSlash: false,
skipTrailingSlashRedirect: true,
reactStrictMode: true,
distDir: 'dist',
images: {
unoptimized: true,
},
pageExtensions: ['js', 'jsx', 'md'],
headers: async () => {
return [
{
source: '/api/(.*)',
headers: getCorsHeaders(),
},
]
},
}

export default withSearch(withMarkdoc({ schemaPath: './src/markdoc' })(withPWA(nextConfig)))
Loading

0 comments on commit 58e861d

Please sign in to comment.