diff --git a/shared-config/README.md b/shared-config/README.md new file mode 100644 index 00000000..34aba680 --- /dev/null +++ b/shared-config/README.md @@ -0,0 +1,71 @@ +# Meeting Notes Example + +### Tutorial article: https://dev.to/encore/setting-up-a-free-production-ready-web-app-backend-in-go-with-database-in-less-than-100-lines-4ge4 + +This is an example application (frontend + backend) for a Markdown Meeting Notes app. + +Live demo: [https://encoredev.github.io/meeting-notes/](https://encoredev.github.io/meeting-notes/) + +![Frontend](./images/demo.gif) + +The backend uses an SQL database to store meeting notes and has three API endpoints: +* `GET /note/:id` - Retrieve a note by ID. +* `POST /note` - Create a new note (or update an existing one). +* `GET /images/:query` - Search for images by using the [Pexels API](https://www.pexels.com/api/). + +## Developing locally + +When you have [installed Encore](https://encore.dev/docs/install), you can create a new Encore application and clone this example by running this command: + +```bash +encore app create my-app --example=meeting-notes +``` + +## Running + +To run the application locally, make sure you have [Docker](https://docker.com) installed and running. This is required to run Encore applications with SQL databases. + +```bash +# Run the backend +encore run + +# In a different terminal window, run the frontend +cd frontend +npm install +npm run dev +``` + +### Encore developer dashboard + +While `encore run` is running, open [http://localhost:9400/](http://localhost:9400/) to view Encore's local developer dashboard. +Here you can see the request you just made and a view a trace of the response. + +## Deployment + +### Backend + +Deploy your backend to a staging environment in Encore's free development cloud. + +```bash +git push encore +``` + +You can view your backend deploys, metrics and traces at [https://app.encore.dev](https://app.encore.dev). + +### Frontend + +#### Using GitHub pages + +1. Create a repo on GitHub +2. In the `vite.config.js` file, set the `base` property to the name of your repo: +```ts +base: "/example-meeting-notes/", +``` +3. Push your code to GitHub and wait for the GitHub actions workflow to finish. +4. Go to *Settings* → *Pages* for your repo on GitHub and set *Branch* to `gh-pages`. + +Your site should now be available at `https://.github.io//`. + +Pushing new code to GitHub will automatically update your site (see the GitHub actions workflow in the `.github` folder). + +[Read more about GitHub pages here](https://docs.github.com/en/pages/getting-started-with-github-pages/creating-a-github-pages-site). diff --git a/shared-config/cue.mod/module.cue b/shared-config/cue.mod/module.cue new file mode 100644 index 00000000..fc28903e --- /dev/null +++ b/shared-config/cue.mod/module.cue @@ -0,0 +1 @@ +module: "encore.app" diff --git a/shared-config/encore.app b/shared-config/encore.app new file mode 100644 index 00000000..30e52bf6 --- /dev/null +++ b/shared-config/encore.app @@ -0,0 +1,4 @@ +{ + "id": "", + "lang": "go" +} diff --git a/shared-config/go.mod b/shared-config/go.mod new file mode 100644 index 00000000..e5370d5f --- /dev/null +++ b/shared-config/go.mod @@ -0,0 +1,5 @@ +module encore.app + +go 1.18 + +require encore.dev v1.44.6 diff --git a/shared-config/go.sum b/shared-config/go.sum new file mode 100644 index 00000000..58aed3bc --- /dev/null +++ b/shared-config/go.sum @@ -0,0 +1,2 @@ +encore.dev v1.44.6 h1:rpwwZxtoQdSC+Oh88GXI7mC1XALgy3YP0vZuRZRxJDQ= +encore.dev v1.44.6/go.mod h1:XdWK6bKKAVzutmOKpC5qzalDQJLNfRCF/YCgA7OUZ3E= diff --git a/shared-config/myservice/config.cue b/shared-config/myservice/config.cue new file mode 100644 index 00000000..9117d494 --- /dev/null +++ b/shared-config/myservice/config.cue @@ -0,0 +1,3 @@ +import "encore.app/sharedconfig:sharedconfig" + +Shared: sharedconfig diff --git a/shared-config/myservice/config.go b/shared-config/myservice/config.go new file mode 100644 index 00000000..9e759f7d --- /dev/null +++ b/shared-config/myservice/config.go @@ -0,0 +1,25 @@ +package config + +import ( + "context" + + "encore.app/sharedconfig" + "encore.dev/config" +) + +type Config struct { + Shared sharedconfig.Config +} + +var cfg = config.Load[*Config]() + +type GetResponse struct { + EnableFoo bool +} + +//encore:api public method=GET path=/config +func Get(_ context.Context) (*GetResponse, error) { + return &GetResponse{ + EnableFoo: cfg.Shared.EnableFoo, + }, nil +} diff --git a/shared-config/myservice/encore.gen.cue b/shared-config/myservice/encore.gen.cue new file mode 100644 index 00000000..9e757ef9 --- /dev/null +++ b/shared-config/myservice/encore.gen.cue @@ -0,0 +1,33 @@ +// Code generated by encore. DO NOT EDIT. +// +// The contents of this file are generated from the structs used in +// conjunction with Encore's `config.Load[T]()` function. This file +// automatically be regenerated if the data types within the struct +// are changed. +// +// For more information about this file, see: +// https://encore.dev/docs/develop/config +package config + +// #Meta contains metadata about the running Encore application. +// The values in this struct will be injected by Encore upon deployment and can be +// referenced from other config values for example when configuring a callback URL: +// CallbackURL: "\(#Meta.APIBaseURL)/webhooks.Handle`" +#Meta: { + APIBaseURL: string @tag(APIBaseURL) // The base URL which can be used to call the API of this running application. + Environment: { + Name: string @tag(EnvName) // The name of this environment + Type: "production" | "development" | "ephemeral" | "test" @tag(EnvType) // The type of environment that the application is running in + Cloud: "aws" | "azure" | "gcp" | "encore" | "local" @tag(CloudType) // The cloud provider that the application is running in + } +} + +// #Config is the top level configuration for the application and is generated +// from the Go types you've passed into `config.Load[T]()`. Encore uses a definition +// of this struct which is closed, such that the CUE tooling can any typos of field names. +// this definition is then immediately inlined, so any fields within it are expected +// as fields at the package level. +#Config: { + Shared: EnableFoo: bool +} +#Config \ No newline at end of file diff --git a/shared-config/myservice/encore.gen.go b/shared-config/myservice/encore.gen.go new file mode 100644 index 00000000..b423e9b7 --- /dev/null +++ b/shared-config/myservice/encore.gen.go @@ -0,0 +1,17 @@ +// Code generated by encore. DO NOT EDIT. + +package config + +import "context" + +// These functions are automatically generated and maintained by Encore +// to simplify calling them from other services, as they were implemented as methods. +// They are automatically updated by Encore whenever your API endpoints change. + +// Interface defines the service's API surface area, primarily for mocking purposes. +// +// Raw endpoints are currently excluded from this interface, as Encore does not yet +// support service-to-service API calls to raw endpoints. +type Interface interface { + Get(ctx context.Context) (*GetResponse, error) +} diff --git a/shared-config/sharedconfig/sharedconfig.cue b/shared-config/sharedconfig/sharedconfig.cue new file mode 100644 index 00000000..198c4de1 --- /dev/null +++ b/shared-config/sharedconfig/sharedconfig.cue @@ -0,0 +1,3 @@ +package sharedconfig + +EnableFoo: true diff --git a/shared-config/sharedconfig/sharedconfig.go b/shared-config/sharedconfig/sharedconfig.go new file mode 100644 index 00000000..653d556b --- /dev/null +++ b/shared-config/sharedconfig/sharedconfig.go @@ -0,0 +1,5 @@ +package sharedconfig + +type Config struct { + EnableFoo bool +}