Make sure you have npm installed, and working on the ./frontend/ directory.
npm installnpm run devCompile and build for frontend (required for Frontend+Backend)
npm run buildThis command generated all the frontend to compiled assets. It makes it possible to host a web server with just these files alone. Frontend+Backend serves these build files alongside the backend.
Lint with ESLint
npm run lintTo start the web appliaction with the static build files generated by Vue alongside the backend, make sure you have Go 1.18 or higher installed, and run:
go run main.goWith this way, the backend API will start routing its own routes, and also serve static build files generated by Vue on the /frontend/dist/ directory. If there is no build files in that directory, you will get a 404, but you are still able to work with backend only.
First, we are going to install air.
go install github.com/cosmtrek/air@latestNext, we need to configure Air for our Golang project. You can do that by running the following command:
air initThis will create a air.toml file that will contain the default configurations for Air. Here is an example of what that looks like:
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"
[build]
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ."
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
kill_delay = "0s"
log = "build-errors.log"
send_interrupt = false
stop_on_error = true
[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"
[log]
time = false
[misc]
clean_on_exit = false
[screen]
clear_on_rebuild = falseNext, let me highlight a few notable configurations you might care about and might want to update for your project.
Under build in the air.toml; you might want to change the cmd property. If the entry of your golang application is in a different directory, say server, you can change the property to something like this:
cmd = "go build -o ./tmp/main ./server/main.go"Finally, the only part that is remaining is running our Golang application using Air. You can do this by running the air command:
airThis project started as a COMP305 Database Management Systems Project for the following members.