You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: app/docs/md/patterns/architect-migration.md
+25-1Lines changed: 25 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,31 @@ Enhance uses file-based routing so that a route handler responds based on its fi
12
12
Enhance project routes are in effect an Architect route handler with the data API and HTML response split into two files. Enhance also includes the Enhance SSR renderer for expanding Custom Elements on the server.
13
13
14
14
## Shared code (shared, views, models, and app)
15
-
If you are familiar with Architect apps they use the convention of a `src/views` and `src/shared` folder to share code between handlers. View code is available only to `GET` routes and shared is available to all handlers. Enhance renames these folders so that views becomes `/app` and shared becomes `/models`.
15
+
If you are familiar with Architect apps they use the convention of a `src/views` and `src/shared` folder to share code between handlers. View code is available only to `GET` routes and shared is available to all handlers. Enhance renames these folders so that views becomes `/app` and shared becomes `/shared`.
16
+
17
+
Any code placed in the `/shared` folder will be accessible from both the Enhance and Architect parts of your project. However, importing it is a bit odd.
18
+
19
+
In your Architect routes, use the `@architect/shared` package as you normally would. For example:
20
+
21
+
<doc-codefilename="src/http/get-notes/index.mjs">
22
+
23
+
```javascript
24
+
importdatafrom'@architect/shared/notes.mjs'
25
+
```
26
+
27
+
</doc-code>
28
+
29
+
From an Enhance API in `app/api` you would use a relative path in your import. For example:
30
+
31
+
<doc-codefilename="app/api/notes.mjs">
32
+
33
+
```javascript
34
+
importnotesfrom'../../shared/notes.mjs'
35
+
```
36
+
37
+
</doc-code>
38
+
39
+
For reference an [example project](https://github.com/macdonst/shared-code) is available.
16
40
17
41
## Convert routes from Architect and Enhance
18
42
An Architect route is defined in the `app.arc` manifest.
0 commit comments