@gasket/template-nextjs-express 1.0.0 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +232 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -0,0 +1,232 @@
1
+ # Gasket Next.js Express Template
2
+
3
+ A full-stack TypeScript web application template built with Gasket, Next.js Pages Router, Express custom server, and internationalization support.
4
+
5
+ ## Overview
6
+
7
+ This template provides a production-ready starting point for building web applications using:
8
+
9
+ - **Next.js 15** with Pages Router - React framework with file-based routing
10
+ - **Express Custom Server** - Full control over server-side rendering and API routes
11
+ - **TypeScript** - Type-safe development with modern JavaScript features
12
+ - **Gasket** - Plugin architecture for extensible applications
13
+ - **React Intl** - Internationalization with multi-language support
14
+ - **Vitest** - Lightning-fast unit testing with React Testing Library
15
+
16
+ ## Features
17
+
18
+ - ✅ **Next.js Pages Router** with TypeScript support
19
+ - ✅ **Custom Express server** for advanced server-side control
20
+ - ✅ **Internationalization** pre-configured with English and French
21
+ - ✅ **Server-side rendering** with Gasket data injection
22
+ - ✅ **API routes** and custom server endpoints capability
23
+ - ✅ **Testing setup** with Vitest, React Testing Library, and JSDOM
24
+ - ✅ **ESLint configuration** with React and Next.js rules
25
+ - ✅ **Development tools** with hot reloading and TypeScript watching
26
+ - ✅ **Production build** optimization
27
+
28
+ ## Quick Start
29
+
30
+ Create a new Next.js Pages Router project with custom Express server:
31
+
32
+ ```bash
33
+ npx create-gasket-app@latest my-app --template @gasket/template-nextjs-express
34
+ ```
35
+
36
+ ## Project Structure
37
+
38
+ ```
39
+ my-app/
40
+ ├── pages/ # Next.js Pages Router
41
+ │ ├── _app.tsx # App component wrapper
42
+ │ ├── _document.ts # Document component
43
+ │ └── index.tsx # Home page component
44
+ ├── components/ # React components
45
+ │ └── head.tsx # Reusable head component
46
+ ├── locales/ # Internationalization files
47
+ │ ├── en-US.json # English translations
48
+ │ └── fr-FR.json # French translations
49
+ ├── test/ # Test files
50
+ ├── gasket.ts # Gasket configuration
51
+ ├── server.ts # Custom Express server
52
+ ├── intl.ts # Internationalization manager
53
+ ├── next.config.js # Next.js configuration
54
+ ├── tsconfig.json # TypeScript configuration
55
+ └── dist/ # Built server files
56
+ ```
57
+
58
+ ## Available Scripts
59
+
60
+ | Script | Description |
61
+ |--------|-------------|
62
+ | `npm run local` | Start development with TypeScript watch and custom server |
63
+ | `npm run build` | Build TypeScript server and Next.js application |
64
+ | `npm run start` | Start production server |
65
+ | `npm run preview` | Build and start production server |
66
+ | `npm run test` | Run unit tests |
67
+ | `npm run test:watch` | Run tests in watch mode |
68
+ | `npm run test:coverage` | Run tests with coverage report |
69
+ | `npm run docs` | Generate and serve documentation |
70
+ | `npm run lint` | Check code style and quality |
71
+
72
+ ## Development
73
+
74
+ ### Custom Express Server
75
+
76
+ The template includes a custom Express server (`server.ts`) that wraps Next.js, giving you full control over:
77
+
78
+ - **Server-side rendering** - Custom SSR logic and data fetching
79
+ - **API routes** - Express routes alongside Next.js API routes
80
+ - **Middleware** - Custom middleware for authentication, logging, etc.
81
+ - **Error handling** - Custom error pages and handling logic
82
+
83
+ The development setup runs two concurrent processes:
84
+ 1. **TypeScript Watch** - Compiles server TypeScript files on change
85
+ 2. **Custom Express Server** - Runs Next.js with `GASKET_DEV=1` for development mode
86
+
87
+ ### Pages Router vs App Router
88
+
89
+ This template uses Next.js Pages Router, which differs from App Router:
90
+
91
+ - **File-based routing** in the `pages/` directory
92
+ - **`_app.tsx`** for global app wrapper and providers
93
+ - **`_document.ts`** for HTML document structure
94
+ - **`getServerSideProps`** and `getStaticProps` for data fetching
95
+ - **API routes** in `pages/api/` directory
96
+
97
+ ## Internationalization
98
+
99
+ The template includes full i18n support with React Intl and `@gasket/react-intl`.
100
+
101
+ ## Pages and Components
102
+
103
+ ### App Component (`pages/_app.tsx`)
104
+
105
+ The app component wraps all pages and includes:
106
+ - **IntlProvider** for internationalization
107
+ - **Router-based locale detection**
108
+ - **Global providers** and context
109
+
110
+ ### Document Component (`pages/_document.ts`)
111
+
112
+ Enhanced with Gasket data injection using `withGasketData`:
113
+
114
+ ```tsx
115
+ import Document from 'next/document';
116
+ import { withGasketData } from '@gasket/nextjs/document';
117
+ import gasket from '@/gasket';
118
+
119
+ export default withGasketData(gasket)(Document);
120
+ ```
121
+
122
+ ### Adding New Pages
123
+
124
+ Create new pages in the `pages/` directory:
125
+
126
+ ```tsx
127
+ // pages/about.tsx
128
+ import Head from '../components/head';
129
+ import { FormattedMessage } from 'react-intl';
130
+
131
+ export default function AboutPage() {
132
+ return (
133
+ <div>
134
+ <Head title="About" description="About our app" />
135
+ <h1><FormattedMessage id="about_title" /></h1>
136
+ </div>
137
+ );
138
+ }
139
+ ```
140
+
141
+ ### API Routes
142
+
143
+ Add API routes in `pages/api/`:
144
+
145
+ ```tsx
146
+ // pages/api/users.ts
147
+ import type { NextApiRequest, NextApiResponse } from 'next';
148
+
149
+ export default function handler(req: NextApiRequest, res: NextApiResponse) {
150
+ if (req.method === 'GET') {
151
+ res.status(200).json({ users: [] });
152
+ } else {
153
+ res.setHeader('Allow', ['GET']);
154
+ res.status(405).end(`Method ${req.method} Not Allowed`);
155
+ }
156
+ }
157
+ ```
158
+
159
+ ## Configuration
160
+
161
+ The template includes these Gasket plugins by default:
162
+
163
+ - `@gasket/plugin-nextjs` - Next.js integration
164
+ - `@gasket/plugin-express` - Express custom server
165
+ - `@gasket/plugin-intl` - Internationalization support
166
+ - `@gasket/plugin-https` - HTTPS and server lifecycle management
167
+ - `@gasket/plugin-webpack` - Webpack configuration
168
+ - `@gasket/plugin-winston` - Structured logging
169
+ - `@gasket/plugin-command` - CLI command support
170
+
171
+ ### Custom Server Routes
172
+
173
+ Add custom Express routes in your `server.ts` or via Gasket plugins:
174
+
175
+ ```typescript
176
+ // Example plugin for custom routes
177
+ export default {
178
+ name: 'api-routes',
179
+ hooks: {
180
+ express(gasket, app) {
181
+ app.get('/api/custom', (req, res) => {
182
+ res.json({ message: 'Custom API endpoint' });
183
+ });
184
+ }
185
+ }
186
+ };
187
+ ```
188
+
189
+ ## Testing
190
+
191
+ The template includes comprehensive testing setup:
192
+
193
+ - **Vitest** - Fast test runner
194
+ - **React Testing Library** - React component testing utilities
195
+ - **JSDOM** - DOM simulation for server-side testing
196
+ - **TypeScript support** - Type-safe tests
197
+
198
+ Write tests in the `test/` directory:
199
+
200
+ ```tsx
201
+ import { render, screen } from '@testing-library/react';
202
+ import { IntlProvider } from 'react-intl';
203
+ import { describe, it, expect } from 'vitest';
204
+ import IndexPage from '@/pages/index';
205
+
206
+ const messages = {
207
+ gasket_welcome: 'Welcome to Gasket!',
208
+ gasket_learn: 'Learn Gasket',
209
+ gasket_edit_page: 'To get started, edit pages/index.js and save to reload.'
210
+ };
211
+
212
+ describe('IndexPage', () => {
213
+ it('renders welcome message', () => {
214
+ render(
215
+ <IntlProvider locale="en-US" messages={messages}>
216
+ <IndexPage />
217
+ </IntlProvider>
218
+ );
219
+ expect(screen.getByText('Welcome to Gasket!')).toBeInTheDocument();
220
+ });
221
+ });
222
+ ```
223
+
224
+ ## Next Steps
225
+
226
+ - Add more pages in the `pages/` directory
227
+ - Create API routes in `pages/api/`
228
+ - Add custom Express middleware and routes
229
+ - Customize the internationalization with additional languages
230
+ - Add database connections and authentication
231
+ - Set up CI/CD pipeline
232
+ - Add more comprehensive testing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gasket/template-nextjs-express",
3
- "version": "1.0.0",
3
+ "version": "7.0.1",
4
4
  "description": "Gasket Next.js Pages Router template with Express",
5
5
  "type": "module",
6
6
  "files": [