-
Notifications
You must be signed in to change notification settings - Fork 7
add Next.js ts example #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
G3root
wants to merge
12
commits into
chiselstrike:main
Choose a base branch
from
G3root:nextjs-ts-example
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f7131be
init project
G3root 9fae143
chore: add required dependencies
G3root c0dce5a
chore: add chisel specific stuff to git ignore
G3root 6b0ef16
feat: add chise.toml file
G3root 4826dfc
feat: add policies.yml file
G3root 01d26e6
feat: add person model
G3root e6438a2
feat: add endpoints
G3root 1f44eba
feat: add Ironsession helper
G3root 9676e03
feat: update index page
G3root 5df8e93
chore: remove unnecessary packages
G3root b4a6ff9
chore: use npm as the package manager
G3root dc7f6da
docs: update readme
G3root File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "extends": "next/core-web-vitals" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
|
||
| # dependencies | ||
| /node_modules | ||
| /.pnp | ||
| .pnp.js | ||
|
|
||
| # testing | ||
| /coverage | ||
|
|
||
| # next.js | ||
| /.next/ | ||
| /out/ | ||
|
|
||
| # production | ||
| /build | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| *.pem | ||
|
|
||
| # debug | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| .pnpm-debug.log* | ||
|
|
||
| # local env files | ||
| .env*.local | ||
|
|
||
| # vercel | ||
| .vercel | ||
|
|
||
| # typescript | ||
| *.tsbuildinfo | ||
|
|
||
| # ChiselStrike | ||
| .chiseld-data.db* | ||
| .chiseld.db* | ||
| .gen |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| models = ["models"] | ||
| endpoints = ["endpoints"] | ||
| policies = ["policies"] | ||
| modules = "node" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # ChiselStrike with Next.js TypeScript Example | ||
|
|
||
| This example showcases using Next.js and ChiselStrike with TypeScript. | ||
|
|
||
| ## Getting Started | ||
|
|
||
| First, clone the files locally: | ||
|
|
||
| ```bash | ||
| npx degit chiselstrike/chiselstrike-examples/nextjs-ts my-app | ||
| ``` | ||
|
|
||
| Go to the project directory: | ||
|
|
||
| ```bash | ||
| cd my-app | ||
| ``` | ||
|
|
||
| Install dependencies: | ||
|
|
||
| ```bash | ||
| npm install | ||
| ``` | ||
|
|
||
| Start the development server: | ||
|
|
||
| ```bash | ||
| npm run dev | ||
| ``` | ||
|
|
||
| This should start Next.js and the ChiselStrike server at the same time. The Next.js server | ||
| should be accessible in [http://localhost:3000](http://localhost:3000), whereas ChiselStrike server should be accessible in [http://localhost:8080](http://localhost:8080). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { ChiselRequest, responseFromJson } from "@chiselstrike/api"; | ||
|
|
||
| import { Person } from "../models/person.model"; | ||
|
|
||
| export default async function chisel(req: ChiselRequest) { | ||
| if (req.method == "POST") { | ||
| const payload = await req.json(); | ||
| const firstName = payload["firstName"]; | ||
| const lastName = payload["lastName"]; | ||
| const created = await Person.create({ firstName, lastName }); | ||
| return responseFromJson(created); | ||
| } | ||
| return responseFromJson("Only POST is allowed", 405); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { ChiselRequest, responseFromJson } from "@chiselstrike/api"; | ||
|
|
||
| import { Person } from "../models/person.model"; | ||
|
|
||
| export default async function chisel(req: ChiselRequest) { | ||
| if (req.method == "GET") { | ||
| try { | ||
| let resp_json: Person[] = []; | ||
| await Person.cursor().forEach((p) => resp_json.push(p)); | ||
| return responseFromJson(resp_json); | ||
| } catch (e) { | ||
| return responseFromJson(e, 500); | ||
| } | ||
| } | ||
| return responseFromJson("Only GET is allowed", 405); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { withIronSessionApiRoute, withIronSessionSsr } from "iron-session/next"; | ||
| import { NextApiHandler } from "next"; | ||
|
|
||
| const sessionOptions = { | ||
| password: "complex_password_at_least_32_characters_long", | ||
| cookieName: "chiselstrike_cookie10", | ||
| // secure: true should be used in production (HTTPS) but can't be used in development (HTTP) | ||
| cookieOptions: { | ||
| secure: process.env.NODE_ENV === "production", | ||
| }, | ||
| }; | ||
|
|
||
| export function withSessionRoute(handler: NextApiHandler) { | ||
| return withIronSessionApiRoute(handler, sessionOptions); | ||
| } | ||
|
|
||
| export function withSessionSsr( | ||
| handler: Parameters<typeof withIronSessionSsr>[0] | ||
| ) { | ||
| return withIronSessionSsr(handler, sessionOptions); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { ChiselEntity } from "@chiselstrike/api"; | ||
|
|
||
| export class Person extends ChiselEntity { | ||
| firstName: string = ""; | ||
| lastName: string = ""; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| /// <reference types="next" /> | ||
| /// <reference types="next/image-types/global" /> | ||
|
|
||
| // NOTE: This file should not be edited | ||
| // see https://nextjs.org/docs/basic-features/typescript for more information. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /** @type {import('next').NextConfig} */ | ||
| const nextConfig = { | ||
| reactStrictMode: true, | ||
| } | ||
|
|
||
| module.exports = nextConfig |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, but what do I do then? Which elements of `http://localhost:3000] demonstrate ChiselStrike and how do I interact with them?