Playground Rust + Vue.js Server

A simple development server built with Rust that serves a Vue.js SPA (Single Page Application).

Features

  • Rust-based static file server
  • SPA Web App support (here Vue.js but you can test other and make feedbacks)
  • Custom web root directory support

Project Structure

  • server/ - Rust backend server
  • web/ - Vue.js frontend application

Installation

  1. Clone the repository:
git clone https://github.com/ludndev/playground-rust-vuejs-server.git
  1. Build and run the frontend:
cd web
npm ci
npm run build
  1. Run the server:
cd server
cargo run

Usage

  • To run the server with a custom web root directory:
cd server
cargo run -- --dir path/to/web/root

If you are following this repository structure, no need to set --dir as default dir is set to web/dist.

With Vue.js SPA

With Vue.js SPA, you can use the following command to run the server. Note that the --dir option is set to ../web/dist for our demo Vue.js app. Feel free to adapt --dir to your actual path.

cargo run -- --dir ../web/dist

With Next.js SPA

Here, we are using Next.js as an example. We have used nobruf/shadcn-landing-page. Our implementation may not cover all cases, but it working for our demo app.

Clone the repository in our project root directory to have a structure like this:

.
├── server/
├── shadcn-landing-page/
└── web/

We have added to nextConfig in next.config.js :

    output: "export", // we have added this line to enable the export mode
    distDir: "build", // we have added this line to change the distDir name

to look like this:

/** @type {import('next').NextConfig} */
const nextConfig = {
  output: "export", // we have added this line to enable the export mode
  distDir: "build", // we have added this line to change the distDir name
  images: {
    remotePatterns: [
      {
        protocol: "https",
        hostname: "i.pravatar.cc",
      },
      {
        protocol: "https",
        hostname: "images.unsplash.com",
      },
      {
        protocol: "https",
        hostname: "github.com",
      },
    ],
  },
};

export default nextConfig;

And finally, to run the server:

cargo run -- --dir ./../shadcn-landing-page/build

License

This project is licensed under the MIT License - see the LICENSE file for details.