whythawk / full-stack-fastapi-postgresql

Full stack, modern web application generator. Using FastAPI, PostgreSQL as database, Nuxt3, Docker, automatic HTTPS and more.
MIT License
231 stars 47 forks source link

Refactor front-end for NuxtJS #3

Closed br3ndonland closed 2 years ago

br3ndonland commented 2 years ago

Description

This PR will replace the front-end code with the Whythawk NuxtJS front-end, updating the project configuration files to match.

Changes

Front-end source code

The front-end source code will be replaced with the code from whythawk/nuxt-for-fastapi.

Dockerfile

A Dockerfile will be added for the whythawk/nuxt-for-fastapi front-end code. The Dockerfile is divided into four build stages:

  1. build:
  2. run-dev: use the build stage to run the dev server, which can hot-reload within the Docker container if the source code is mounted
  3. run-start: use the build stage to run nuxt start, with all dependencies from the build
  4. run-minimal: this image is less than 1/6 the size of the others (262 MB vs. 1.72 GB)
    • Pull a Node.js image running on Alpine Linux
    • Copy the built Nuxt.js app from the build stage, without node_modules
    • Install nuxt-start, with the minimal runtime for Nuxt.js (needed in addition to the inlined dependencies from standalone mode)
    • Run the nuxt start command using the nuxt-start module to start the SSR application

To work with the Docker configuration:

cd /path/to/full-stack-fastapi-postgresql/{{cookiecutter.project_slug}}/frontend

# build and run the development environment with hot-reloading
docker build . --rm --target run-dev -t localhost/whythawk/nuxt-for-fastapi:run-dev
docker run -it -p 3000:3000 -v $(pwd):/app --env-file $(pwd)/.env localhost/whythawk/nuxt-for-fastapi:run-dev

# build and run the minimal production environment
docker build . --rm --target run-minimal -t localhost/whythawk/nuxt-for-fastapi:run-minimal
docker run --env-file $(pwd)/.env -it -p 3000:3000 localhost/whythawk/nuxt-for-fastapi:run-minimal

Then browse to http://localhost:3000 to see the homepage.

Docker Compose

The front-end Dockerfile will also be integrated into the Docker Compose configuration. This requires only minor modifications:

Nuxt.js configuration variables are poorly documented, but here are some links for reference:

Documentation

READMEs will be updated with new project info and screenshots.