Skip to content

Commit 1047b3c

Browse files
committed
Merge branch 'i11-项目结构和代码优化(复杂)'
2 parents 048375a + a1f3756 commit 1047b3c

12 files changed

+429
-36
lines changed

Dockerfile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Base on offical Node.js Alpine image
2+
FROM node:alpine
3+
4+
# Set working directory
5+
WORKDIR /usr/app
6+
7+
# Install PM2 globally
8+
RUN npm install --global pm2 --registry=https://registry.npm.taobao.org
9+
10+
# Copy package.json and package-lock.json before other files
11+
# Utilise Docker cache to save re-installing dependencies if unchanged
12+
COPY ./package*.json ./
13+
14+
# Copy all files
15+
COPY ./ ./
16+
17+
# Build app
18+
RUN yarn config set registry https://registry.npm.taobao.org/
19+
RUN yarn
20+
RUN yarn build
21+
22+
# Run container as non-root (unprivileged) user
23+
# The node user is provided in the Node.js Alpine base image
24+
USER node
25+
EXPOSE 8888
26+
27+
RUN ls -alh
28+
29+
# Run npm start script with PM2 when container starts
30+
CMD [ "pm2-runtime", "start", "ecosystem.config.js" ]

ecosystem.config.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = {
2+
apps: [
3+
{
4+
name: 'geese',
5+
script: './server.js',
6+
instances: 2,
7+
max_restarts: 3,
8+
env: {
9+
NEXT_PUBLIC_ENV: 'production',
10+
},
11+
watch: true,
12+
merge_logs: true,
13+
exec_mode: 'cluster',
14+
max_memory_restart: '1G',
15+
instance_var: 'NODE_APP_INSTANCE',
16+
log_date_format: 'YYYY-MM-DD HH:mm:ss:SS',
17+
error_file: '/data/logs/geese_error.log',
18+
out_file: '/data/logs/geese_out.log',
19+
},
20+
],
21+
};

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"dev": "NODE_OPTIONS='--inspect' next dev",
77
"build": "next build",
88
"start": "next start",
9+
"server_start": "pm2 start ecosystem.config.js",
10+
"server_reload": "pm2 reload ecosystem.config.js",
11+
"server_stop": "pm2 stop ecosystem.config.js",
912
"lint": "next lint",
1013
"lint:fix": "eslint src --fix && yarn format",
1114
"lint:strict": "eslint --max-warnings=0 src",
@@ -26,6 +29,7 @@
2629
"copy-to-clipboard": "^3.3.2",
2730
"dayjs": "^1.11.3",
2831
"eslint-plugin-react": "^7.30.1",
32+
"express": "^4.18.1",
2933
"next": "^12.1.6",
3034
"rc-image": "^5.7.0",
3135
"react": "^18.1.0",

public/fonts/inter-var-latin.woff2

-35.7 KB
Binary file not shown.

public/svg/Vercel.svg

-1
This file was deleted.

server.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
const next = require('next');
3+
const dev = process.env.NEXT_PUBLIC_ENV !== 'production';
4+
const app = next({ dev });
5+
const handle = app.getRequestHandler();
6+
7+
const { parse } = require('url');
8+
9+
const express = require('express');
10+
const expressRouter = express.Router();
11+
const server = express();
12+
13+
const NODE_PORT = 8888;
14+
15+
app.prepare().then(() => {
16+
expressRouter.get('*', (req, res) => {
17+
// 页面路由
18+
const parsedUrl = parse(req.url, true);
19+
const { pathname, query } = parsedUrl;
20+
console.log('process.env.NEXT_PUBLIC_ENV: ', process.env.NEXT_PUBLIC_ENV);
21+
console.log('pathname: ', pathname);
22+
return app.render(req, res, pathname, query);
23+
});
24+
server.use('/', expressRouter);
25+
26+
server.all('*', (req, res) => {
27+
// Be sure to pass `true` as the second argument to `url.parse`.
28+
// This tells it to parse the query portion of the URL.
29+
const parsedUrl = parse(req.url, true);
30+
31+
return handle(req, res, parsedUrl);
32+
});
33+
34+
server.listen(NODE_PORT, () =>
35+
console.log('App listening on port ' + NODE_PORT)
36+
);
37+
});

src/pages/_document.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ class MyDocument extends Document {
1616
return (
1717
<Html lang='en'>
1818
<Head>
19-
<link
19+
{/* <link
2020
rel='preload'
2121
href='/fonts/inter-var-latin.woff2'
2222
as='font'
2323
type='font/woff2'
2424
crossOrigin='anonymous'
25-
/>
25+
/> */}
2626
</Head>
2727
<body>
2828
<Main />

src/styles/globals.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
@layer base {
3434
/* inter var - latin */
35-
@font-face {
35+
/* @font-face {
3636
font-family: 'Inter';
3737
font-style: normal;
3838
font-weight: 100 900;
@@ -41,7 +41,7 @@
4141
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
4242
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212,
4343
U+2215, U+FEFF, U+FFFD;
44-
}
44+
} */
4545

4646
.cursor-newtab {
4747
cursor: url('/images/new-tab.png') 10 10, pointer;

src/utils/api.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ const PRODUCTION_API_HOST = 'https://api.hellogithub.com';
88
const API_ROOT_PATH = '/v1';
99

1010
export const API_HOST =
11-
process.env.NEXT_PUBLIC_ENV === 'production'
12-
? PRODUCTION_API_HOST
13-
: LOCAL_API_HOST;
11+
process.env.NEXT_PUBLIC_ENV === 'development'
12+
? LOCAL_API_HOST
13+
: PRODUCTION_API_HOST;
1414

1515
/**
1616
* Generates a url to make an api call to our backend

tailwind.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = {
1616
theme: {
1717
extend: {
1818
fontFamily: {
19-
primary: ['Inter', ...fontFamily.sans],
19+
primary: [...fontFamily.sans],
2020
},
2121
colors: {
2222
primary: {

vercel.json

-13
This file was deleted.

0 commit comments

Comments
 (0)