Skip to content

Commit

Permalink
Moved examples/thoughts to Wasp TS config. (#2337)
Browse files Browse the repository at this point in the history
* Moved examples/thoughts to Wasp TS config.

* fix
  • Loading branch information
Martinsos authored Oct 10, 2024
1 parent db5fddb commit 8cdb575
Show file tree
Hide file tree
Showing 9 changed files with 1,954 additions and 2,504 deletions.
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The **tutorials** directory contains [Wasp tutorial](https://wasp-lang.dev/docs/

1. **thoughts**
- A simple note-taking app organized around the concept of hashtags.
- Demonstrates: [db seeding](https://wasp-lang.dev/docs/data-model/backends#seeding-the-database), [auth](https://wasp-lang.dev/docs/auth/overview), [rpc](https://wasp-lang.dev/docs/data-model/operations/overview)
- Demonstrates: [db seeding](https://wasp-lang.dev/docs/data-model/backends#seeding-the-database), [auth](https://wasp-lang.dev/docs/auth/overview), [rpc](https://wasp-lang.dev/docs/data-model/operations/overview), [Wasp TS config](https://wasp-lang.dev/docs/general/wasp-ts-config) .

1. **streaming**
- Demonstrates: **http streaming**, [api](https://wasp-lang.dev/docs/advanced/apis)
Expand Down
6 changes: 5 additions & 1 deletion examples/thoughts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ Thoughts

**Thoughts** is a note-taking app organized around the concept of hashtags.

Run `wasp start` to start the app in development mode.
## Running

Run `wasp start` to start the app in development mode. Make sure that you have database running first: easiest way is to run `wasp start db`.

## Deployment

This app is deployed at https://wasp-thoughts-client.fly.dev/ : client, server and db on Fly.io .

Expand Down
53 changes: 0 additions & 53 deletions examples/thoughts/main.wasp

This file was deleted.

49 changes: 49 additions & 0 deletions examples/thoughts/main.wasp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { App, ExtImport } from 'wasp-config'

const app = new App('Thoughts', {
title: 'Thoughts',
wasp: { version: '^0.15.0' }
});

app.db({
seeds: [{ import: 'devSeedBasic', from: '@src/server/seeds.js' }]
});

app.auth({
userEntity: 'User',
methods: { usernameAndPassword: {} },
onAuthFailedRedirectTo: '/login'
});

appPageWithRoute('Main', '/', '@src/client/MainPage.jsx', { auth: true });
appPageWithRoute('Thoughts', '/thoughts', '@src/client/ThoughtsPage.jsx', { auth: true });
appPageWithRoute('Login', '/login', '@src/client/LoginPage.jsx');
appPageWithRoute('Signup', '/signup', '@src/client/SignupPage.jsx');

appAction('createThought', ['Thought', 'Tag'], '@src/server/actions.js');
appQuery( 'getTags', ['Tag'], '@src/server/queries.js');
appQuery( 'getThoughts', ['Thought'], '@src/server/queries.js');

function appPageWithRoute(pageName: string, path: string, from: ExtImport['from'], config?: { auth: boolean }) {
const page = app.page(pageName, {
component: { importDefault: pageName, from },
...(config?.auth && { authRequired: config?.auth })
});
app.route(pageName + 'Route', { path, to: page });
}

function appQuery(jsName: string, entities: string[], from: ExtImport['from']) {
app.query(jsName, {
fn: { import: jsName, from },
entities
});
}

function appAction(jsName: string, entities: string[], from: ExtImport['from']) {
app.action(jsName, {
fn: { import: jsName, from },
entities
});
}

export default app;
Loading

0 comments on commit 8cdb575

Please sign in to comment.