Skip to content

Commit 9de02bd

Browse files
Add template engine example (#151)
1 parent 29aeaf7 commit 9de02bd

File tree

14 files changed

+1014
-0
lines changed

14 files changed

+1014
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ environment. Use the appropriate command for your system:
7171
| [ts/expressjs-migration](ts/expressjs-migration) | Express.js migration guide examples | APIs, Raw Endpoints, Auth, Databases |
7272
| [ts/file-upload](ts/file-upload) | Upload files from frontend example | Raw Endpoints |
7373
| [ts/static-files](ts/static-files) | Serving static files example | Static Endpoints |
74+
| [ts/template-engine](ts/template-engine) | Using a templating engine | Raw Endpoints, Static Endpoints |
7475

7576
† = Cannot be installed using `encore app create --example`, create an empty app and clone the repo instead.
7677

ts/template-engine/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.encore
2+
encore.gen.go
3+
encore.gen.cue
4+
/.encore
5+
node_modules
6+
/encore.gen

ts/template-engine/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Template Engine with Encore.ts
2+
3+
This example utilizes a Raw endpoint to serve views through a template engine. The example implementation uses [EJS](https://ejs.co/) for rendering views, but the same approach is also applicable for other template engines.
4+
5+
## Developing locally
6+
7+
### Prerequisite: Installing Encore
8+
9+
If this is the first time you're using Encore, you first need to install the CLI that runs the local development
10+
environment. Use the appropriate command for your system:
11+
12+
- **macOS:** `brew install encoredev/tap/encore`
13+
- **Linux:** `curl -L https://encore.dev/install.sh | bash`
14+
- **Windows:** `iwr https://encore.dev/install.ps1 | iex`
15+
16+
When you have installed Encore, run:
17+
18+
```bash
19+
encore app create --example=ts/template-engine
20+
```
21+
22+
## Running locally
23+
24+
```bash
25+
encore run
26+
```
27+
28+
**Pages:**
29+
30+
- <http://localhost:4000/person> - Serving a specific view with data
31+
- <http://localhost:4000/> - Serving a template based on the dynamic path
32+
- <http://localhost:4000/about/contact> - Serving a template located in a sub-folder
33+
- <http://localhost:4000/html> - Serving an inline HTML template
34+
35+
Open [http://localhost:4000](http://localhost:4000) in your browser to see the example frontend.
36+
37+
You can also access Encore's [local development dashboard](https://encore.dev/docs/observability/dev-dash) on <http://localhost:9400/> to view traces, API documentation, and more.
38+
39+
## Deployment
40+
41+
Deploy your application to a staging environment in Encore's free development cloud:
42+
43+
```bash
44+
git add -A .
45+
git commit -m 'Commit message'
46+
git push encore
47+
```
48+
49+
Then head over to the [Cloud Dashboard](https://app.encore.dev) to monitor your deployment and find your production URL.
50+
51+
From there you can also connect your own AWS or GCP account to use for deployment.
52+
53+
Now off you go into the clouds!

ts/template-engine/encore.app

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"id": "",
3+
"lang": "typescript",
4+
"build": {
5+
"docker": {
6+
"bundle_source": true
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)