forked from bloom-housing/bloom
-
Notifications
You must be signed in to change notification settings - Fork 1
/
next.config.js
105 lines (97 loc) · 4.03 KB
/
next.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* eslint-env node */
/* eslint-disable @typescript-eslint/no-var-requires */
const withTM = require("next-transpile-modules")(["@bloom-housing"])
const withSass = require("@zeit/next-sass")
const withCSS = require("@zeit/next-css")
const withMDX = require("@next/mdx")()
const axios = require("axios")
if (process.env.NODE_ENV !== "production") {
require("dotenv").config()
}
// Set up app-wide constants
let LISTING_SERVICE_URL = "http://localhost:3001"
if (process.env.INCOMING_HOOK_BODY && process.env.INCOMING_HOOK_BODY.startsWith("http")) {
// This is a value that can get set via a Netlify webhook for branch deploys
LISTING_SERVICE_URL = decodeURIComponent(process.env.INCOMING_HOOK_BODY)
} else if (process.env.LISTING_SERVICE_URL) {
LISTING_SERVICE_URL = process.env.LISTING_SERVICE_URL
}
console.log(`Using ${LISTING_SERVICE_URL} for the listing service.`)
const MAPBOX_TOKEN =
process.env.MAPBOX_TOKEN ||
"pk.eyJ1IjoibWplZHJhcyIsImEiOiJjazI2OHA5YzQycTBpM29xdDVwbXNyMDlwIn0.XS5ilGzTh_yVl3XY-8UKeA"
const HOUSING_COUNSELOR_SERVICE_URL = process.env.HOUSING_COUNSELOR_SERVICE_URL
// Load the Tailwind theme and set up SASS vars
const bloomTheme = require("./tailwind.config.js")
const tailwindVars = require("@bloom-housing/ui-components/tailwind.tosass.js")(bloomTheme)
// Tell webpack to compile the ui components package
// https://www.npmjs.com/package/next-transpile-modules
module.exports = withCSS(
withMDX(
withSass(
withTM({
env: {
listingServiceUrl: LISTING_SERVICE_URL,
mapBoxToken: MAPBOX_TOKEN,
housingCounselorServiceUrl: HOUSING_COUNSELOR_SERVICE_URL,
gtmKey: process.env.GTM_KEY || null,
},
sassLoaderOptions: {
prependData: tailwindVars,
},
// exportPathMap adapted from https://github.com/zeit/next.js/blob/canary/examples/with-static-export/next.config.js
async exportPathMap() {
// we fetch our list of listings, this allow us to dynamically generate the exported pages
let listings = []
try {
const response = await axios.get(LISTING_SERVICE_URL)
listings = response.data.listings
} catch (error) {
console.log(error)
}
// tranform the list of posts into a map of pages with the pathname `/post/:id`
const listingPaths = listings.reduce(
(listingPaths, listing) =>
Object.assign({}, listingPaths, {
[`/listing/${listing.id}/${listing.urlSlug}`]: {
page: "/listing",
query: { id: listing.id },
},
// Create a redirect so that the base ID redirects to the ID with URL slug
[`/listing/${listing.id}`]: {
page: "/redirect",
query: { to: `/listing/${listing.id}/${listing.urlSlug}` },
},
}),
{}
)
// define page paths for various available languages
const translatablePaths = Object.assign({}, listingPaths, {
"/": { page: "/" },
"/listings": { page: "/listings" },
"/housing-counselors": { page: "/HousingCounselors" },
"/additional-resources": { page: "/AdditionalResources" },
})
const languages = ["es"] // add new language codes here
const languagePaths = {}
Object.entries(translatablePaths).forEach(([key, value]) => {
languagePaths[key] = value
languages.forEach((language) => {
const query = Object.assign({}, value.query)
query.language = language
languagePaths[`/${language}${key.replace(/^\/$/, "")}`] = {
...value,
query: query,
}
})
})
// combine the map of all various types of page paths
return Object.assign({}, languagePaths, {
"/disclaimer": { page: "/disclaimer" },
"/privacy": { page: "/privacy" },
})
},
})
)
)
)