Git Product home page Git Product logo

aspirewithvitesample's Introduction

Sample Project Aspire+Vite

This repo is just a sample project for issue #1898

Setup

yarn:

git clone https://github.com/dersia/AspireWithViteSample.git
cd AspireWithViteSample/AspireWithViteSample.Frontend
yarn

npm:

git clone https://github.com/dersia/AspireWithViteSample.git
cd AspireWithViteSample/AspireWithViteSample.Frontend
npm i

!set the environment variable PORT before you start! Powershell: $env:PORT = 3000 Bash: PORT=300

start:

yarn dev
``

```bash
npm run dev

Issue

There are 2 Projects:

  • ASPNET Web Api called Backend. This is a basic Web Api project, just created from template, nothing changed
  • Vite React-Ts called Frontend This is a basic Vite project created with yarn create-vite --template react-ts

The solution also contains a .NET Aspire Project. In the Aspire Project both the backend and the frontend are added to the builder. The Backend is added as a Reference (WithReference(backend)) to the Frontend. Running the Aspire Project brings up both Backend and Frontend and the Backend Service url is added to the Environment Variables as expected. The Frontend project uses vite in the App.tsx to load the Backend Url from the Environment Variables const backendurl = import.meta.env.services__backend__1 and outputs it <p className='read-the-docs'>Backend url: {backendurl}</p>.

To start this using Aspire make sure you have set AspireWithViteSample.AppHost as the starting project and hit F5.

Vite Environment Variables

Vite only takes Environment Variables into consideration that are prefixed with VITE_. This is for security purposes to make sure that no environment variables are exposed, that are not supposed to be exposed. If you add the environment variable manually Powershell: $env:VITE_services__backend__1 = http://localhost:backendport Bash: VITE_services__backend__1=http://localhost:backendport and change const backendurl = import.meta.env.services__backend__1 to const backendurl = import.meta.env.VITE_services__backend__1

and start the vite app it all works as expected and the backendurl will be displayed

aspirewithvitesample's People

Contributors

dersia avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.