Skip to content

Commit b9cd37b

Browse files
committed
feat(passport): use vue replace django template
1 parent b13ec29 commit b9cd37b

13 files changed

Lines changed: 509 additions & 8 deletions

File tree

rootfs/api/settings/production.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
TEMPLATES = [
5656
{
5757
'BACKEND': 'django.template.backends.django.DjangoTemplates',
58-
'DIRS': [os.path.join(BASE_DIR, 'templates')],
58+
'DIRS': [os.path.join(BASE_DIR, '..', "web", "dist")],
5959
'APP_DIRS': True,
6060
'OPTIONS': {
6161
'context_processors': [
@@ -74,6 +74,7 @@
7474
MIDDLEWARE = [
7575
'corsheaders.middleware.CorsMiddleware',
7676
'django.middleware.security.SecurityMiddleware',
77+
'whitenoise.middleware.WhiteNoiseMiddleware',
7778
'django.middleware.clickjacking.XFrameOptionsMiddleware',
7879
'django.middleware.csrf.CsrfViewMiddleware',
7980
'django.contrib.sessions.middleware.SessionMiddleware',
@@ -89,12 +90,12 @@
8990
WSGI_APPLICATION = 'api.wsgi.application'
9091

9192
INSTALLED_APPS = (
93+
'whitenoise.runserver_nostatic',
9294
'django.contrib.admin',
9395
'django.contrib.auth',
9496
'django.contrib.contenttypes',
9597
'django.contrib.sessions',
9698
'django.contrib.messages',
97-
'django.contrib.staticfiles',
9899
'django.contrib.humanize',
99100
# Third-party apps
100101
'corsheaders',
@@ -343,8 +344,10 @@
343344

344345
# Static files (CSS, JavaScript, Images)
345346
# https://docs.djangoproject.com/en/2.2/howto/static-files/
346-
STATIC_URL = '/static/'
347-
STATIC_ROOT = os.path.abspath(os.path.join(BASE_DIR, 'static'))
347+
STATIC_URL = '/assets/'
348+
#STATIC_ROOT = os.path.abspath(os.path.join(BASE_DIR, 'static'))
349+
STATIC_ROOT = os.path.abspath(os.path.join(BASE_DIR, '..', 'web', 'dist', 'assets'))
350+
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
348351

349352
# see: https://django-oauth-toolkit.readthedocs.io/en/latest/oidc.html?highlight=oidc.key#creating-rsa-private-key # noqa
350353
with open('/var/run/secrets/drycc/passport/oidc-rsa-private-key') as f:

rootfs/passport/urls.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
from django.urls import path
1717
from django.conf.urls import include, url
1818
from django.contrib import admin
19-
from django.views import static
19+
from django.views.generic.base import TemplateView
2020
from api.settings import production
2121
from api.views import LivenessCheckView, ReadinessCheckView
2222

2323
urlpatterns = [
2424
path('admin/', admin.site.urls),
25-
url(r'^static/(?P<path>.*)$', static.serve,
26-
{'document_root': production.STATIC_ROOT}, name='static'),
25+
path(r'', TemplateView.as_view(template_name="index.html")),
2726
url(r'^healthz$', LivenessCheckView.as_view()),
2827
url(r'^readiness$', ReadinessCheckView.as_view()),
29-
url(r'^', include('api.urls')),
28+
url(r'^api', include('api.urls')),
3029
]

rootfs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ requests-toolbelt==0.9.1
1212
django_redis==4.12.1
1313
dj-database-url==0.5.0
1414
django-oauth-toolkit==1.5.0
15+
whitenoise==5.3.0

rootfs/web/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
.DS_Store
3+
dist
4+
dist-ssr
5+
*.local

rootfs/web/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" href="/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite App</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="/src/main.js"></script>
12+
</body>
13+
</html>

rootfs/web/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "web",
3+
"version": "0.0.0",
4+
"scripts": {
5+
"dev": "vite",
6+
"build": "vite build",
7+
"serve": "vite preview"
8+
},
9+
"dependencies": {
10+
"vue": "^3.0.5"
11+
},
12+
"devDependencies": {
13+
"@vitejs/plugin-vue": "^1.3.0",
14+
"@vue/compiler-sfc": "^3.0.5",
15+
"vite": "^2.4.4"
16+
}
17+
}

rootfs/web/public/favicon.ico

4.19 KB
Binary file not shown.

rootfs/web/src/App.vue

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<template>
2+
<img alt="Vue logo" src="./assets/logo.png" />
3+
<HelloWorld msg="Hello Vue 3 + Vite" />
4+
</template>
5+
6+
<script setup>
7+
import HelloWorld from './components/HelloWorld.vue'
8+
9+
// This starter template is using Vue 3 experimental <script setup> SFCs
10+
// Check out https://github.com/vuejs/rfcs/blob/master/active-rfcs/0040-script-setup.md
11+
</script>
12+
13+
<style>
14+
#app {
15+
font-family: Avenir, Helvetica, Arial, sans-serif;
16+
-webkit-font-smoothing: antialiased;
17+
-moz-osx-font-smoothing: grayscale;
18+
text-align: center;
19+
color: #2c3e50;
20+
margin-top: 60px;
21+
}
22+
</style>

rootfs/web/src/assets/logo.png

6.69 KB
Loading
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<template>
2+
<h1>{{ msg }}</h1>
3+
4+
<p>
5+
<a href="https://vitejs.dev/guide/features.html" target="_blank">
6+
Vite Documentation
7+
</a>
8+
|
9+
<a href="https://v3.vuejs.org/" target="_blank">Vue 3 Documentation</a>
10+
</p>
11+
12+
<button type="button" @click="state.count++">
13+
count is: {{ state.count }}
14+
</button>
15+
<p>
16+
Edit
17+
<code>components/HelloWorld.vue</code> to test hot module replacement.
18+
</p>
19+
</template>
20+
21+
<script setup>
22+
import { defineProps, reactive } from 'vue'
23+
24+
defineProps({
25+
msg: String
26+
})
27+
28+
const state = reactive({ count: 0 })
29+
</script>
30+
31+
<style scoped>
32+
a {
33+
color: #42b983;
34+
}
35+
</style>

0 commit comments

Comments
 (0)