Skip to content

Commit

Permalink
local https and ssr auth (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
MauserBitfly authored Apr 18, 2024
1 parent b472115 commit 99f8b34
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
3 changes: 3 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ logs
pnpm-lock.yaml

.npmrc

server.crt
server.key
14 changes: 13 additions & 1 deletion frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ Look at the [Nuxt 3 documentation](https://nuxt.com/docs/getting-started/introdu

## Setup

Set the following mapping in your `/etc/hosts` file
`127.0.0.1 local.beaconcha.in`

Create server certificates for locally running on https, by runing this comands in the console
```bash
openssl genrsa 2048 > server.key
chmod 400 server.key
openssl req -new -x509 -nodes -sha256 -days 365 -key server.key -out server.crt
```
Set the following env variable (needed to load local mock data):
`export NODE_TLS_REJECT_UNAUTHORIZED=0`

Make sure to install the dependencies:

copy .npmrc-example to .npmrc and replace YOURKEY with your fontawesome API key
Expand All @@ -33,7 +45,7 @@ bun install

## Development Server

Start the development server on `http://localhost:3000`:
Start the development server on `https://local.beaconcha.in:3000/`:

```bash
# npm
Expand Down
3 changes: 0 additions & 3 deletions frontend/components/bc/DataWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ const { getUser } = useUserStore()
await useAsyncData('get_user', () => getUser())
// TODO: load user on server once we fix SSR
await useAsyncData('get_user', () => getUser(), { server: false })
</script>
<template>
<slot />
Expand Down
5 changes: 3 additions & 2 deletions frontend/composables/useCustomFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ const mapping: Record<string, MappingData> = {
}

export function useCustomFetch () {
const headers = useRequestHeaders(['cookie'])
const { showError } = useBcToast()
const { t: $t } = useI18n()

Expand All @@ -168,11 +169,11 @@ export function useCustomFetch () {
let baseURL = map.mock ? '../mock' : map.legacy ? legacyApiClient : apiClient

if (process.server) {
baseURL = map.mock ? `${url.origin}/mock` : map.legacy ? pConfig?.legacyApiServer : pConfig?.apiServer
baseURL = map.mock ? `${url.origin.replace('http:', 'https:')}/mock` : map.legacy ? pConfig?.legacyApiServer : pConfig?.apiServer
}

options.headers = new Headers({ ...options.headers, ...headers })
if (apiKey) {
options.headers = new Headers({})
options.headers.append('Authorization', `Bearer ${apiKey}`)
}
options.credentials = 'include'
Expand Down
6 changes: 6 additions & 0 deletions frontend/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ try {

export default defineNuxtConfig({
devtools: { enabled: true },
devServer: {
https: {
key: 'server.key',
cert: 'server.crt'
}
},
runtimeConfig: {
public: {
apiClient: '',
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "module",
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"dev": "nuxt dev --host=local.beaconcha.in",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare",
Expand Down

0 comments on commit 99f8b34

Please sign in to comment.