Skip to content

Commit e18ffd6

Browse files
committed
fix(shared): correct env load
1 parent ed55b53 commit e18ffd6

File tree

6 files changed

+12
-17
lines changed

6 files changed

+12
-17
lines changed

.github/workflows/deploy.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ jobs:
1212
deploy:
1313
runs-on: ubuntu-22.04
1414

15+
env:
16+
PUBLIC_API_URL: ${{ secrets.PUBLIC_API_URL }}
17+
1518
steps:
1619
- name: Checkout 🛎️
1720
uses: actions/checkout@v3
@@ -33,8 +36,6 @@ jobs:
3336

3437
- name: Build 🛠️
3538
run: pnpm build:prod
36-
env:
37-
API_PROJECTS_URL: ${{ secrets.API_PROJECTS_URL }}
3839

3940
- name: Deploy 🚀
4041
uses: JamesIves/github-pages-deploy-action@v4

astro.config.mjs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import { loadEnv } from 'vite'
12
import { defineConfig } from 'astro/config'
23
import { getAstroConfig } from 'shared/config/astro'
34

4-
const config = getAstroConfig()
5+
const { PUBLIC_API_URL } = loadEnv('', '', 'PUBLIC')
6+
const { hostname } = new URL(PUBLIC_API_URL)
7+
const config = getAstroConfig({ hostname })
58

69
// https://astro.build/config
710
export default defineConfig(config)

packages/shared/config/astro.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ import icon from 'astro-icon'
22
import tailwind from '@astrojs/tailwind'
33
import type { AstroUserConfig } from 'astro/config'
44

5-
import { API_URL } from '../consts'
6-
75
export interface GetAstroConfig {
86
project?: string
7+
hostname?: string
98
}
109

11-
export function getAstroConfig ({ project }: GetAstroConfig = {}): AstroUserConfig {
10+
export function getAstroConfig ({ project, hostname }: GetAstroConfig = {}): AstroUserConfig {
1211
const assets = 'assets'
13-
const { hostname } = new URL(API_URL)
1412
const hasProjectName = typeof project === 'string'
1513
const outDir = hasProjectName ? `../../dist/${project}` : undefined
1614
const base = hasProjectName ? `/frontendmentor/${project}` : '/frontendmentor'
@@ -22,8 +20,6 @@ export function getAstroConfig ({ project }: GetAstroConfig = {}): AstroUserConf
2220
build: {
2321
assets
2422
},
25-
image: {
26-
domains: [hostname]
27-
}
23+
image: hostname ? { domains: [hostname] } : undefined
2824
}
2925
}

packages/shared/consts.ts

-3
This file was deleted.

src/layouts/Layout.astro

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
import { get } from 'shared/utils/http'
3-
import { API_URL } from 'shared/consts'
43
import MetaTags from 'shared/components/MetaTags.astro'
54
65
import Header from '@/components/Header.astro'
@@ -35,7 +34,7 @@ interface Landing {
3534
}
3635
}
3736
38-
const { footer, header } = await get<Landing>(API_URL + '/landing/')
37+
const { footer, header } = await get<Landing>(import.meta.env.PUBLIC_API_URL + '/landing/')
3938
const { designedBy, developedBy } = footer
4039
const { navigation, profile } = header
4140
---

src/pages/index.astro

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
import { get } from 'shared/utils/http'
3-
import { API_URL } from 'shared/consts'
43
54
import Card from '@/components/Card.astro'
65
import Layout from '@/layouts/Layout.astro'
@@ -17,7 +16,7 @@ interface Projects {
1716
title: string
1817
}
1918
20-
const { results } = await get<{ results: Projects[] }>(API_URL + '/projects/')
19+
const { results } = await get<{ results: Projects[] }>(import.meta.env.PUBLIC_API_URL + '/projects/')
2120
const hasProjects = results.length > 0
2221
---
2322

0 commit comments

Comments
 (0)