import { WEBPACK_OUTPUT_PATH } from 'serverSettings'
import { ENV, WEBPACK_DEV_URL, BAKED_BASE_URL } from 'settings'
import * as fs from 'fs-extra'
import urljoin = require('url-join')
import * as path from 'path'

let manifest: {[key: string]: string}
export function webpack(assetName: string, context?: string) {
    if (ENV === 'production') {
        // Read the real asset name from the manifest in case it has a hashed filename
        if (!manifest) {
            const manifestPath = path.join(WEBPACK_OUTPUT_PATH, 'manifest.json')
            manifest = JSON.parse(fs.readFileSync(manifestPath).toString('utf8'))
        }
        assetName = manifest[assetName]

        return urljoin('/assets', assetName)
    } else {
        if (assetName.match(/\.js$/)) {
            assetName = `js/${assetName}`
        } else if (assetName.match(/\.css$/)) {
            assetName = `css/${assetName}`
        }

        return urljoin(WEBPACK_DEV_URL, assetName)
    }
}
import { WEBPACK_OUTPUT_PATH } from 'serverSettings'
import { ENV, WEBPACK_DEV_URL, BAKED_BASE_URL } from 'settings'
import * as fs from 'fs-extra'
import urljoin = require('url-join')
import * as path from 'path'

let manifest: {[key: string]: string}
export function webpack(assetName: string, context?: string) {
    if (ENV === 'production') {
        // Read the real asset name from the manifest in case it has a hashed filename
        if (!manifest) {
            const manifestPath = path.join(WEBPACK_OUTPUT_PATH, 'manifest.json')
            manifest = JSON.parse(fs.readFileSync(manifestPath).toString('utf8'))
        }
        assetName = manifest[assetName]

        return urljoin(BAKED_BASE_URL, '/assets', assetName)
    } else {
        if (assetName.match(/\.js$/)) {
            assetName = `js/${assetName}`
        } else if (assetName.match(/\.css$/)) {
            assetName = `css/${assetName}`
        }

        return urljoin(WEBPACK_DEV_URL, assetName)
    }
}
Revert "fix: remove host from assets URL"
Revert "fix: remove host from assets URL"

This reverts commit 563a0eb56f513262180a1db17eec1e56297ff717. It caused the SDG tracker to not load charts, as we use the native embeds there too.
