-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.txt
378 lines (279 loc) · 12.1 KB
/
setup.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
npm init -y
npm install react react-dom next --save
Add the following scripts to package.json:
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
}
mkdir -p src/pages
touch src/pages/index.js
Configure Typescript
touch tsconfig.json
npm install --save-dev typescript @types/react @types/node
mv src/pages/index.js src/pages/index.tsx
npm run dev
Set up Express
When you run npm run dev, basically Next.js starts its own server but it’s possible to handle it programmatically with your own Express server.
We need to install express and its Typescript definitions:
npm install express --save
npm install --save-dev @types/express ts-node
mkdir -p server
touch server/index.ts
Let’s edit the dev script in package.json:
"scripts": {
"dev": "ts-node server/index.ts",
...
}
ts-node is a TypeScript execution and REPL for node.js, with source map support. (source)
Now run npm run dev. But oops, we got an error:
The problem comes from tsconfig.json, there is a line "module": "esnext". Typically, Next.js forces TS compiling with the ESNext pattern but express was built on the commonjs pattern. If you change the value from esnext to commonjs, Next.js will automatically revert it back.
To come over this issue, let’s create another config file:
touch tsconfig.server.json
To breakdown:
"extends": "./tsconfig.json": Gets all options from tsconfig.json
"compilerOptions.module": "commonjs": Use commonjs as the module pattern in order to make both express and next work together.
"compilerOptions.outDir": "dist": This option is used for production. It will compile all .ts files in the server directory to .js and send to the dist directory.
"compilerOptions.noEmit": true: This option is used for production. Next.js basically uses babel to compile Typescript so TS compiler won’t output .js . We will override this value to tell TS compiler compile and output our server files.
"include": ["server"]: This option is also used for production. It lets the TS Compiler know only compiling .ts files in the server/ directory.
We’re gonna use this config for local development. Now we need to edit the dev script again:
"dev": "ts-node --project tsconfig.server.json server/index.ts"
Additionally, when you visit an unknown page say http://localhost:3000/no-exist-page, you will get Internal Server Error instead of a message like 404 not found. This because Next.js no longer handles errors when integrating with a custom server.
The solution is to create a custom error page:
touch src/pages/_error.tsx
Let’s go production
Before spinning up the server in production mode, we need to compile both Next.js and server code to .js. Now, modify scripts in package.json:
"scripts": {
"build:server": "tsc --project tsconfig.server.json",
"build:next": "next build",
"build": "npm run build:next && npm run build:server",
"start": "NODE_ENV=production node dist/index.js"
}
Breakdown:
build:server: Build server code to dist directory
build:next: Build the Next.js application
build: Run both build:server and build:next
start: Run the server. It runs node dist/index.js instead of next start because now we let express handle the server.
Let’s build all the stuff by running npm run build and you should see the result like this:
npm run build
Now run npm start and let’s see our application working in production:
npm start
----------
generate secret
openssl rand -hex 32
----
auth nextjs
npm install --save next-auth
----
test
npm run dev
----
mysql db schema
CREATE TABLE accounts
(
id INT NOT NULL AUTO_INCREMENT,
compound_id VARCHAR(255) NOT NULL,
user_id INTEGER NOT NULL,
provider_type VARCHAR(255) NOT NULL,
provider_id VARCHAR(255) NOT NULL,
provider_account_id VARCHAR(255) NOT NULL,
refresh_token TEXT,
access_token TEXT,
access_token_expires TIMESTAMP(6),
created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
updated_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
PRIMARY KEY (id)
);
CREATE TABLE sessions
(
id INT NOT NULL AUTO_INCREMENT,
user_id INTEGER NOT NULL,
expires TIMESTAMP(6) NOT NULL,
session_token VARCHAR(255) NOT NULL,
access_token VARCHAR(255) NOT NULL,
created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
updated_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
PRIMARY KEY (id)
);
CREATE TABLE users
(
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(255),
email VARCHAR(255),
email_verified TIMESTAMP(6),
image VARCHAR(255),
created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
updated_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
PRIMARY KEY (id)
);
CREATE TABLE verification_requests
(
id INT NOT NULL AUTO_INCREMENT,
identifier VARCHAR(255) NOT NULL,
token VARCHAR(255) NOT NULL,
expires TIMESTAMP(6) NOT NULL,
created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
updated_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
PRIMARY KEY (id)
);
CREATE UNIQUE INDEX compound_id
ON accounts(compound_id);
CREATE INDEX provider_account_id
ON accounts(provider_account_id);
CREATE INDEX provider_id
ON accounts(provider_id);
CREATE INDEX user_id
ON accounts(user_id);
CREATE UNIQUE INDEX session_token
ON sessions(session_token);
CREATE UNIQUE INDEX access_token
ON sessions(access_token);
CREATE UNIQUE INDEX email
ON users(email);
CREATE UNIQUE INDEX token
ON verification_requests(token);
-------------
encryption of jwt
@jayliew Assuming you're talking about the next-auth-example and have done no modifications aside from what you mention in that post, then you need to add additional parameters when you call jwt.getToken (so update this page in the example)
Per https://next-auth.js.org/configuration/options#jwt (emphasis added):
The getToken() helper requires the following options:
req - (object) Request object
secret - (string) JWT Secret
You must also pass any options configured on the jwt option to the helper.
e.g. Including custom session maxAge and custom signing and/or encryption keys or options
So anything you include in the jwt object in [...nextauth].js: needs to be passed to the call. It's all passed as one object, so order doesn't matter but the property name does. In practice that would look like:
// Ideally these values would be in your .env.local (or whatever) file:
const encryption = true,
const signingKey = '{"kty":"oct","kid":"N3XHc3Yy [** SNIP **] SXh9igamUr0","alg":"HS512","k":"MDBwE [** SNIP **] DPgdYUXRQ4"}', // npx node-jose-tools newkey -s 256 -t oct -a HS512
const encryptionKey = '{"kty":"oct","kid":"ouRBLOiCuKyAos [** SNIP **] xrrJwK24","alg":"A256GCM","k":"9NtdI1sk7W [** SNIP **] 4WDLUaVDeg"}', // node-jose-tools newkey -s 256 -t oct -a A256GCM
const secret = 'SYkp4S6ZhU/09XEWRtDA [** SNIP **] VwdwsP//EclhNA==', // openssl rand -base64 64
jwt.getToken({
req, secret, signingKey, encryptionKey, encryption,
})
----------------------
pm2
pm2 start npm --name "codingtest" -- start
------------
Ts.ED Framework
for Node.js and TypeScript
Build your awesome server-side application
npm install --save-dev typescript @types/express
$ npm install --save @tsed/core @tsed/di @tsed/common @tsed/schema @tsed/json-mapper @tsed/exceptions @tsed/platform-express @types/node @types/multer
---------------------------------
Installation
from npm
npm install tor-request
from source
git clone https://github.com/talmobi/tor-request
cd tor-request
npm install
Requirements
A Tor client.
Either run it yourself locally (recommended) or specify the address for a publically available one.
Tor is available for a multitude of systems.
On Debian/Ubuntu you can install and run a relatively up to date Tor with.
apt-get install tor # should auto run as daemon after install
Misc Linux Command for running Tor as daemon --RunAsDaemon 1 thanks @knoxcard
/usr/bin/tor --RunAsDaemon 1
On OSX you can install with homebrew
brew install tor
tor # run tor
-----------------
Open /etc/tor/torrc file with your preferred editor and add the next lines in the end of the file.
# Open 4 SOCKS ports, each providing a new Tor circuit.
SocksPort 9050
SocksPort 9052
SocksPort 9053
SocksPort 9054
----in aws
sudo apt-get install tor
sudo nano /etc/tor/torrc
# Open 4 SOCKS ports, each providing a new Tor circuit.
SocksPort 9050
SocksPort 9052
SocksPort 9053
SocksPort 9054
sudo /etc/init.d/tor restart
-----in macos
To have launchd start tor now and restart at login:
brew services start tor
Or, if you don't want/need a background service you can just run:
tor
/usr/local/etc/tor/torrc
Misc Linux Command for running Tor as daemon --RunAsDaemon 1 thanks @knoxcard
/usr/local/bin/tor --RunAsDaemon 1
-------------
Heroku to work with puppeter pending try to work with Tor
https://buildpack-registry.s3.amazonaws.com/buildpacks/jontewks/puppeteer.tgz
nodejs v14.15.5
npm run dev #development
npm run build #production build
npm start #production
git add --all
git commit -m "Fixed socket io singleton srv on same port "
git push -u origin master
-----------
npm install tailwindcss --save
npx tailwind init --full
Created Tailwind CSS config file: tailwind.config.js
We have two more things to do before wrapping up our TailwindCSS setup. First, create a postcss.config.js file and add the following content
module.exports = {
plugins: ["tailwindcss"]
}
add the following content:
Create a styles.css file at the root level of your project and add the following content:
/* styles.css */
@tailwind base;
@tailwind components;
@tailwind utilities;
create a _app.js file in your pages directory and add the following content
import '../styles.css'
export default function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
--------------------------
connect ORM TypeORM
-------------------
npm install --save typeorm pg reflect-metadata
npm install --save @babel/plugin-proposal-decorators babel-plugin-transform-typescript-metadata @babel/core
npm install --save-dev @babel/plugin-proposal-class-properties @babel/plugin-proposal-decorators babel-plugin-transform-typescript-metadata
----------
Very good
<tbody>
{rows.map((row) => {
return <ObjectRow key={row.uniqueId} />;
})}
</tbody>
This is arguably the best approach because it uses a property that is unique for each item in the dataset. For example, if rows contains data fetched from a database, one could use the table's Primary Key (which typically is an auto-incrementing number).
The best way to pick a key is to use a string that uniquely identifies a list item among its siblings. Most often you would use IDs from your data as keys
-----------
SWR is a React Hooks library for data fetching.
The name “SWR” is derived from stale-while-revalidate, a cache invalidation strategy popularized by HTTP RFC 5861. SWR first returns the data from cache (stale), then sends the request (revalidate), and finally comes with the up-to-date data again.
With just one hook, you can significantly simplify the data fetching logic in your project. And it also covered in all aspects of speed, correctness, and stability to help you build better experiences:
Fast, lightweight and reusable data fetching
Transport and protocol agnostic
Built-in cache and request deduplication
Real-time experience
Revalidation on focus
Revalidation on network recovery
Polling
Pagination and scroll position recovery
SSR and SSG
Local mutation (Optimistic UI)
Built-in smart error retry
TypeScript
React Suspense
React Native
...and a lot more.
With SWR, components will get a stream of data updates constantly and automatically. Thus, the UI will be always fast and reactive.
npm install swr --save
---------
redis cache
npm install next-redis-cache --save
npm install --save @types/redis
npm install redis --save
---------------
docker compose -f docker-compose-redis.yml -f docker-compose-dev.yml build
docker compose -f docker-compose-redis.yml -f docker-compose-dev.yml up
docker compose -f docker-compose-redis.yml -f docker-compose-dev.yml down
Just testing github hooks