-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
994 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import typing | ||
|
||
Key = typing.TypeVar("Key") | ||
Value = typing.TypeVar("Value") | ||
|
||
|
||
def filter_mapping_obj( | ||
mapping_obj: typing.Mapping[Key, Value], *, selected_keys: typing.Iterable | ||
) -> typing.Dict[Key, Value]: | ||
""" | ||
Selects the items in a mapping object (dict, etc.) | ||
""" | ||
|
||
return {key: mapping_obj[key] for key in selected_keys if key in mapping_obj} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
from django.urls import path, re_path | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djproject.settings") | ||
django_asgi_app = get_asgi_application() | ||
|
||
from channels.auth import AuthMiddlewareStack | ||
from channels.routing import ProtocolTypeRouter, URLRouter | ||
from django.conf import settings | ||
|
||
from django_nextjs.proxy import NextJSProxyHttpConsumer, NextJSProxyWebsocketConsumer | ||
|
||
# put your custom routes here if you need | ||
http_routes = [re_path(r"", django_asgi_app)] | ||
websocket_routers = [] | ||
|
||
if settings.DEBUG: | ||
http_routes.insert(0, re_path(r"^(?:_next|__next|next).*", NextJSProxyHttpConsumer.as_asgi())) | ||
websocket_routers.insert(0, path("_next/webpack-hmr", NextJSProxyWebsocketConsumer.as_asgi())) | ||
|
||
|
||
application = ProtocolTypeRouter( | ||
{ | ||
# Django's ASGI application to handle traditional HTTP and websocket requests. | ||
"http": URLRouter(http_routes), | ||
"websocket": AuthMiddlewareStack(URLRouter(websocket_routers)), | ||
# ... | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% extends "django_nextjs/document_base.html" %} | ||
|
||
|
||
{% block head %} | ||
<title>head</title> | ||
{{ block.super }} | ||
<meta name="description" content="head"> | ||
{% endblock %} | ||
|
||
|
||
{% block body %} | ||
<span>pre_body_{{ request.path_info }}</span> | ||
{{ block.super }} | ||
<span>post_body_{{ request.path_info }}</span> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from django.contrib import admin | ||
from django.urls import include, path | ||
|
||
from django_nextjs.render import render_nextjs_page | ||
|
||
|
||
async def nextjs_page(request): | ||
return await render_nextjs_page(request) | ||
|
||
|
||
async def nextjs_page_with_template(request): | ||
return await render_nextjs_page(request, "index.html") | ||
|
||
|
||
urlpatterns = [ | ||
path("admin/", admin.site.urls), | ||
path("", nextjs_page), | ||
path("app", nextjs_page_with_template), | ||
path("app/second", nextjs_page_with_template), | ||
path("page", nextjs_page_with_template), | ||
path("page/second", nextjs_page_with_template), | ||
path("", include("django_nextjs.urls")), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
WSGI config for sample project. | ||
It exposes the WSGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djproject.settings") | ||
|
||
application = get_wsgi_application() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env python | ||
"""Django's command-line utility for administrative tasks.""" | ||
import os | ||
import sys | ||
|
||
|
||
def main(): | ||
"""Run administrative tasks.""" | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djproject.settings") | ||
try: | ||
from django.core.management import execute_from_command_line | ||
except ImportError as exc: | ||
raise ImportError( | ||
"Couldn't import Django. Are you sure it's installed and " | ||
"available on your PYTHONPATH environment variable? Did you " | ||
"forget to activate a virtual environment?" | ||
) from exc | ||
execute_from_command_line(sys.argv) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Link from "next/link"; | ||
|
||
export default function Home() { | ||
return ( | ||
<div> | ||
<div>/app</div> | ||
<Link href="/app/second" id="2"> | ||
/app/second | ||
</Link> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Link from "next/link"; | ||
|
||
export default function Home() { | ||
return ( | ||
<div> | ||
<div>/app/second</div> | ||
<Link href="/app" id="1"> | ||
/app | ||
</Link> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.