Skip to content

Commit

Permalink
fix: working .env
Browse files Browse the repository at this point in the history
  • Loading branch information
sargon64 committed Aug 13, 2023
1 parent 4cf6ebe commit b3e8301
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 17 deletions.
3 changes: 0 additions & 3 deletions .env.example

This file was deleted.

3 changes: 3 additions & 0 deletions apps/web/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# apps/web
BEATFORGE_API_URL=
BEATFORG_GITHUB_CALLBACK_URL=
4 changes: 2 additions & 2 deletions apps/web/src/lib/components/layout/NavBar.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { get } from 'svelte/store';
import { env } from '$env/dynamic/public';
// import { env } from '$env/dynamic/public';
import { Link } from 'ui/link';
import { Button } from 'ui/button';
import { Dropdown } from 'ui/dropdown';
Expand Down Expand Up @@ -44,7 +44,7 @@
<!-- <Link variant="secondary" href={apiURL}>
Login
</Link> -->
<a href={env.PUBLIC_GITHUB_CALL_URL} class="flex items-center gap-2"> Login </a>
<a href={import.meta.env.GITHUB_CALLBACK_URL} class="flex items-center gap-2"> Login </a>
{/if}
</div>
</div>
6 changes: 3 additions & 3 deletions apps/web/src/routes/callback/github/+page.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { env } from '$env/dynamic/public';
// import { env } from '$env/dynamic/public';
import type { PageLoad } from './$types';
import { redirect } from '@sveltejs/kit';

Expand All @@ -9,8 +9,8 @@ export const load = (async ({ url: { searchParams }, fetch }) => {
throw redirect(302, '/');
} else {
try {
console.log(`${env.PUBLIC_API_URL}/auth/github?code=${code}`);
const response = await fetch(`${env.PUBLIC_API_URL}/auth/github?code=${code}`, {
console.log(`${import.meta.env.API_URL}/auth/github?code=${code}`);
const response = await fetch(`${import.meta.env.API_URL}/auth/github?code=${code}`, {
method: 'POST',
headers: {
'Access-Control-Allow-Origin': '*',
Expand Down
3 changes: 1 addition & 2 deletions apps/web/src/routes/mod/[mod]/+page.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { PageLoad } from './$types';
import { env } from '$env/dynamic/public';

export const load = (async ({ params, fetch }) => {
const slug = params.mod;
try {
const response = await fetch(`${env.PUBLIC_API_URL}/graphql`, {
const response = await fetch(`${import.meta.env.API_URL}/graphql`, {
method: 'POST',
headers: {
'content-type': 'application/json'
Expand Down
3 changes: 1 addition & 2 deletions apps/web/src/routes/profile/[id]/+page.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { PageLoad } from './$types';
import { env } from '$env/dynamic/public';

export const load = (async ({ params, fetch }) => {
const id = params.id;
try {
const response = await fetch(`${env.PUBLIC_API_URL}/graphql`, {
const response = await fetch(`${import.meta.env.API_URL}/graphql`, {
method: 'POST',
headers: {
'content-type': 'application/json'
Expand Down
28 changes: 24 additions & 4 deletions apps/web/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import { defineConfig, loadEnv } from 'vite';

export default defineConfig({
plugins: [sveltekit()]
});
export default defineConfig(({ mode }) => {
// let env = loadEnv(mode, process.cwd(), '');
// if (!env.API_URL) env.API_URL = process.env.BEATFORGE_API_URL;
// if (!env.GITHUB_CALLBACK_URL) env.GITHUB_CALLBACK_URL = process.env.BEATFORGE_GITHUB_CALLBACK_URL;


let file_env = loadEnv(mode, process.cwd(), 'BEATFORGE');
const env = {
API_URL: process.env.BEATFORGE_API_URL ?? file_env.BEATFORGE_API_URL,
GITHUB_CALLBACK_URL: process.env.BEATFORGE_GITHUB_CALLBACK_URL ?? file_env.BEATFORGE_GITHUB_CALLBACK_URL
};

if (!env.API_URL) throw new Error('BEATFORGE_API_URL is not defined');
if (!env.GITHUB_CALLBACK_URL) throw new Error('BEATFORGE_GITHUB_CALLBACK_URL is not defined');

return {
plugins: [sveltekit()],
define: {
'import.meta.env.API_URL': JSON.stringify(env.API_URL),
'import.meta.env.GITHUB_CALLBACK_URL': JSON.stringify(env.GITHUB_CALLBACK_URL),
}
}
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"build": "turbo run build",
"dev": "dotenv -- turbo run dev",
"docker:web" : " pnpm run --filter=\"web\" build && node apps/web/build",
"lint:cspell": "cspell --exclude \"apps/**/*\" --exclude \"packages/**/*\" \"**/*\"",
"lint:prettier": "prettier --check --ignore-path=.prettierignore.root .",
"lint:packages": "turbo run lint",
Expand Down
2 changes: 1 addition & 1 deletion web.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ WORKDIR /app/apps/web/

# Expose the port
EXPOSE 3000
CMD ["node", "build"]
CMD ["npm", "run", "docker", "web"]

0 comments on commit b3e8301

Please sign in to comment.