-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Bundle UI into coderd; add ./develop.sh script (#28)
This change bundles the static assets like we have for v1 - using the [`embed`](https://pkg.go.dev/embed) go package. Fixes #22 In addition, it sets up a development script that runs `coderd` locally and serves the front-end, with hot-reloading. The script used is `./develop.sh`: ![2022-01-14 17 30 14](https://user-images.githubusercontent.com/88213859/149603926-f673d3d3-ba12-4eda-bcdd-427252405480.gif) > NOTE: The UI is still placeholder, of course. Need to start testing out a simple, placeholder flow for the new v2 world as a next step Summary of changes: - Add build steps for `go` in the `Makefile` - Add a step for production build, in which we use the `embed` tag - Add a step for development, which doesn't need the `embed` tag - so we don't need to build the front-end twice - Add `next export` build step to output front-end artifacts in `out` - Add a `site` package for `go` - Add `embed_static.go` and `embed.go`. This is mostly brought in as-is from v1, except removing some intercom/sentry CSP entries that we aren't using. - Add a [next development server](https://nextjs.org/docs/advanced-features/custom-server) - Add a `v2-dev` script, that runs `coderd` and the `next` dev server side-by-side - Use the `site` package as the fallback handler. - Add `.gitignore` entries for additional build collateral
- Loading branch information
1 parent
5c49f1f
commit 4dc6e35
Showing
15 changed files
with
909 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,8 @@ yarn-error.log | |
# Front-end ignore | ||
.next/ | ||
site/.next/ | ||
coverage/ | ||
coverage/ | ||
|
||
# Build | ||
bin/ | ||
site/out/ |
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 |
---|---|---|
|
@@ -13,4 +13,5 @@ yarn-error.log | |
# Front-end ignore | ||
.next/ | ||
site/.next/ | ||
site/out/ | ||
coverage/ |
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
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 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
PROJECT_ROOT="$(git rev-parse --show-toplevel)" | ||
cd "${PROJECT_ROOT}" | ||
|
||
# Do initial build - a dev build for coderd. | ||
# It's OK that we don't build the front-end before - because the front-end | ||
# assets are handled by the `yarn dev` devserver. | ||
make bin/coderd | ||
|
||
# This is a way to run multiple processes in parallel, and have Ctrl-C work correctly | ||
# to kill both at the same time. For more details, see: | ||
# https://stackoverflow.com/questions/3004811/how-do-you-run-multiple-programs-in-parallel-from-a-bash-script | ||
(trap 'kill 0' SIGINT; CODERV2_HOST=http://127.0.0.1:3000 yarn dev & ./bin/coderd) |
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
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
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,42 @@ | ||
import express from "express" | ||
import { createProxyMiddleware } from "http-proxy-middleware" | ||
import next from "next" | ||
|
||
const port = process.env.PORT || 8080 | ||
const dev = process.env.NODE_ENV !== "production" | ||
|
||
let coderV2Host = "http://127.0.0.1:3000" | ||
|
||
if (process.env.CODERV2_HOST) { | ||
if (!/^http(s)?:\/\//.test(process.env.CODERV2_HOST)) { | ||
throw new Error("CODERV2_HOST must be http(s)") | ||
} else { | ||
coderV2Host = process.env.CODERV2_HOST | ||
} | ||
} | ||
|
||
console.log(`Using CODERV2_HOST: ${coderV2Host}`) | ||
|
||
const app = next({ dev, dir: "./site" }) | ||
const handle = app.getRequestHandler() | ||
|
||
app | ||
.prepare() | ||
.then(() => { | ||
const server = express() | ||
server.use( | ||
"/api", | ||
createProxyMiddleware("/api", { | ||
target: coderV2Host, | ||
ws: true, | ||
secure: false, | ||
changeOrigin: true, | ||
}), | ||
) | ||
server.all("*", (req, res) => handle(req, res)) | ||
server.listen(port) | ||
}) | ||
.catch((err) => { | ||
console.error(err) | ||
process.exit(1) | ||
}) |
Oops, something went wrong.