This repo hosts the code for the FRCDesign Onshape App.
This repo is intended to be run with VSCode on Linux using WSL Ubuntu.
The local dev environment typically needs either Google Chrome or Firefox to work correctly with Onshape.
Other browsers, such as Brave, can have default security policies that prevent the dev environment from working with Onshape.
Create a new file in the root of this project named .env and add the following contents:
# Server config
VERBOSE_LOGGING=true # Set to false to reduce logging output
# Onshape API Keys (Optional)
API_ACCESS_KEY=<Your API Access Key>
API_SECRET_KEY=<Your API Secret Key>
# OAuth
OAUTH_CLIENT_ID=<Your OAuth client id>
OAUTH_CLIENT_SECRET=<Your OAuth client secret>
SESSION_SECRET=gNSzdRbs4dJYz0obHfeRwaD+u5QbZgJx+V8/rgUH6AiOdoppP3wjeaM97nZmxeJa
# One of admin, editor, or user, depending on desired access to the app. Does nothing in production.
ACCESS_LEVEL_OVERRIDE=admin
NODE_ENV=development
To test Onshape app changes, you will need to create an OAuth application in the Onshape Developer Portal. Fill out the following information:
- Name: (Arbitrary) FRC Design App Test
- Primary format: (Arbitrary) com.frc-design-app.dev
- Summary: (Arbitrary) Test for the FRC Design App.
- Redirect URLs:
https://localhost:3000/auth/callback - OAuth URL:
https://localhost:3000/auth/sign-in - Check the permissions
can read your profile information,can read your documents,can write to your documents, andcan delete your documents and workspaces.
Click Create application, then copy your OAuth app's OAuth client secret (from the popup) and OAuth client identifier into your .env file.
Next, add the necessary Extensions to your OAuth application so you can see it in documents you open:
- Open your OAuth application in the Onshape Developer Portal.
- Go to the Extensions tab.
- Create two extensions with the following properties:
- Name: (Arbitrary) FRC Design App Test
- Location: Element right panel
- Context: Inside assembly/Inside part studio
- Action URL:
- Assembly:
https://localhost:3000/init?elementType=ASSEMBLY&documentId={$documentId}&instanceType={$workspaceOrVersion}&instanceId={$workspaceOrVersionId}&elementId={$elementId} - Part Studio:
https://localhost:3000/init?elementType=PARTSTUDIO&documentId={$documentId}&instanceType={$workspaceOrVersion}&instanceId={$workspaceOrVersionId}&elementId={$elementId}
- Assembly:
- Icon: You'll need an icon. A good choice is the one at
/frontend/public/frc-design-dev-icon.svg.
- Open the Onshape App Store and go to My apps. Find your App and Subscribe to it.
- If it doesn't show up, try creating a Store Entry first.
You should now be able to see your Test App in the right panel of any Part Studios or Assemblies you open.
This step is only required if you want to use the Onshape API from local Python scripts using a KeyApi instance.
- Get an API key from the Onshape developer portal.
- Add your access key and secret key to
.env.
Note that Onshape has an annual limit of 2,500 API calls per Onshape account. This amount is not very large, so you should take pains to be careful with your usage in testing in local environments.
In particular, avoid loading large documents into your local environment and only force reload the database when necessary.
Onshape requires all apps, even temporary test apps, to use https. This creates a big headache for local development.
You can get around this by using mkcert to create a self signed certificate which your browser will trust.
- Install mkcert on your local machine (not in the dev container!).
If you are on Windows, this will likely mean installing Chocolately and running
choco install mkcertusing a Powershell terminal you run as an Administrator. - Create a local Certificate Authority (CA):
mkcert -install
- Create a localhost certificate (localhost-key.pem and localhost.pem) and copy them into the root of this project:
cd ~ # Switch to your user directory
cd Documents # Switch to the Documents folder - you can also use any other folder you recognize, like Downloads
mkcert localhost # Create a certificate which allows localhost to run
- You can then open your Documents folder in File Explorer and copy and paste
localhost-key.pemandlocalhost.peminto the root of this project.
If you use a chromium-based browser like Google Chrome, MKCert should install the certificate automatically. If it doesn't, you'll need to add the Certificate Authority manually. In Firefox, the procedure is:
- In PowerShell, run
mkcert -CAROOTand note down the path. - Open Firefox and go to
Settings > Certificates > View Certificates... > Authorities > Import... - Navigate to the
CAROOTpath and selectrootCA.pem.
Install nvm (node version manager) in your WSL container, install npm, and then install the dependencies:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | bash
nvm i node
npm i
You should now be able to run the Launch dev VSCode task to launch Vite.
You should then be able to launch the FRC Design App from the right panel of any Onshape Part Studio or Assembly and see the FRC Design App UI appear.
To see documents, add one or more documents and push a new app version to rebuild the search database.
To view the state of Cloudflare, type e in Vite to launch the local Cloudflare UI instance.
Double check your Action URLs configured in Onshape. You can also open Browser Dev Tools (usually F12), then open the app in Onshape and see if any errors or warnings appear in the Console or the Network tab.
Occasionally, a process will fail to fully shut down, causing problems when you next attempt to Launch servers since the port is already taken.
If a process fails to start because a port is already taken, you can kill the process squatting on the port by running lsof -i :<port number>, e.g., lsof -i :8080, to get the PID of the process.
You can then kill the process using kill <PID> (or, possibly, kill -9 <PID>).