Skip to content
Draft
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
5360fc9
Update next
Josehower Jun 19, 2023
896f69e
Remove Fly deploy
Josehower Jun 19, 2023
99f045e
Configure for railway
Josehower Jun 19, 2023
21cfc53
Update webpack config
Josehower Jun 20, 2023
5513174
Use canvas externals in webpack
Josehower Jun 20, 2023
73f34ad
Use ENV variable from vercel
Josehower Jun 20, 2023
9e70757
Use ligth JSDOM lib
Josehower Jun 20, 2023
4074dd3
Update lock
Josehower Jun 20, 2023
fe22997
Remove extra webpack config
Josehower Jun 20, 2023
d90acd5
Add vercel fix suggestion
Josehower Jun 20, 2023
af6f979
Update to use different canvas
Josehower Jun 20, 2023
dd55c34
Use different dom lib
Josehower Jun 20, 2023
281ba8f
Remove canvas
Josehower Jun 20, 2023
d9ebf98
Use new JSDOM lib
Josehower Jun 20, 2023
aa1c96e
Update to trigger deploy
Josehower Jun 20, 2023
61d93f6
Use ESM
Josehower Jun 22, 2023
27a6367
Use ESM
Josehower Jun 26, 2023
f900e10
Update object
Josehower Jun 26, 2023
8b14159
Update ssl
Josehower Jun 26, 2023
53e81a3
Use default export
Josehower Jun 26, 2023
25bb8b5
Update next
Josehower Jun 27, 2023
fd69555
Remove Fly deploy
Josehower Jun 19, 2023
a8482d9
Configure for railway
Josehower Jun 19, 2023
f8e9a7f
Update sass
Josehower Jun 27, 2023
afc6f2f
Update dependencies
Josehower Jun 27, 2023
b2957c1
Update lock
Josehower Jun 27, 2023
3fc307f
Merge branch 'main' into vercel-deploy
Josehower Jun 27, 2023
7f9e56a
Delete ley.config.js
karlhorky Jun 27, 2023
33c31b6
Update types
Josehower Jun 27, 2023
2331a16
Add generic
Josehower Jun 27, 2023
d829dae
Add types
Josehower Jun 27, 2023
7bd396a
Discard changes to ...rkflows/lint-check-types-build-deploy.yml
karlhorky Jun 30, 2023
9828dd4
Update lint-check-types-build-deploy.yml
karlhorky Jun 30, 2023
392d455
Discard changes to ...rkflows/lint-check-types-build-deploy.yml
karlhorky Jun 30, 2023
21cafe0
Create lint-check-types-build-deploy.yml
karlhorky Jun 30, 2023
7c01333
Discard changes to scripts/fly-io-start.sh
karlhorky Jun 30, 2023
e30ad76
Update next.config.js
karlhorky Jun 30, 2023
c5ffe0f
Add back deleted file
karlhorky Jun 30, 2023
51ea59d
Update config file to work
Josehower Jun 30, 2023
76e8678
Update dependency upgrades - non-major (#97)
Josehower Jun 30, 2023
2071c6f
Update dependency eslint-config-upleveled to v5 (#98)
renovate[bot] Jun 30, 2023
2e35968
Enable deployment to both Fly and Vercel (#96)
Josehower Jun 30, 2023
d0a3fff
Remove Fly deploy
Josehower Jun 30, 2023
c75a75f
Configure for railway
Josehower Jun 19, 2023
5933f1e
Use ligth JSDOM lib
Josehower Jun 20, 2023
0894cc2
Update object
Josehower Jun 26, 2023
19c51b6
Update ssl
Josehower Jun 26, 2023
d3d60bc
Add back removed deploy step
karlhorky Jun 30, 2023
32f0518
Rename lint-check-types-build.yml to lint-check-types-build-deploy.yml
karlhorky Jun 30, 2023
5c96612
Create fly-io-start.sh
karlhorky Jun 30, 2023
fe782aa
Create fly.toml
karlhorky Jun 30, 2023
e661e69
Fix dockerfile
Josehower Jun 30, 2023
afc7e2b
Delete ley.config.js
karlhorky Jun 30, 2023
b5b186c
Update connect
Josehower Jun 30, 2023
bc86540
Merge branch 'main' into vercel-deploy
Josehower Jun 30, 2023
181b96b
Update lock
Josehower Jun 30, 2023
c39d258
Use Boolean constructor instead of !!
Josehower Jun 30, 2023
a4be47b
Use sinfle file for jsdom types
Josehower Jun 30, 2023
baa4d62
Remove unnecesary configuration
Josehower Jun 30, 2023
7bc5af8
Merge branch 'main' into vercel-deploy
karlhorky Jun 30, 2023
be48c35
Update tsconfig.json
karlhorky Jun 30, 2023
31abf21
Merge branch 'main' into vercel-deploy
karlhorky Jun 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,3 @@ jobs:
API_KEY: ${{ secrets.API_KEY }}
- name: Run Stylelint
run: pnpm stylelint '**/*.{css,scss,less,js,tsx}'
deploy:
name: Deploy to Fly.io
runs-on: ubuntu-latest
needs: lint-and-check-types-and-build
if: github.ref == 'refs/heads/main'
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
13 changes: 7 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Initialize builder layer
FROM node:18-alpine AS builder
ENV NODE_ENV production
ARG DATABASE_URL
ENV DATABASE_URL=$DATABASE_URL
# Install necessary tools
RUN apk add --no-cache libc6-compat yq build-base g++ cairo-dev jpeg-dev pango-dev giflib-dev --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community
# Install pnpm
Expand All @@ -16,7 +18,7 @@ RUN pnpm build
FROM node:18-alpine AS runner
ENV NODE_ENV production
# Install necessary tools
RUN apk add bash postgresql cairo pango jpeg musl giflib pixman pangomm libjpeg-turbo freetype
RUN apk add bash cairo pango jpeg musl giflib pixman pangomm libjpeg-turbo freetype
# Install pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app
Expand All @@ -32,8 +34,7 @@ COPY --from=builder /app/package.json ./
COPY --from=builder /app/.env.production ./
COPY --from=builder /app/next.config.js ./

# Copy start script and make it executable
COPY --from=builder /app/scripts ./scripts
RUN chmod +x /app/scripts/fly-io-start.sh

CMD ["./scripts/fly-io-start.sh"]
ARG PORT
ENV PORT=$PORT
CMD ["pnpm", "migrate", "up"]
CMD ["pnpm", "start"]
2 changes: 1 addition & 1 deletion app/example-6-cross-site-scripting/solution-2/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import DOMPurify from 'dompurify';
import { JSDOM } from 'jsdom';
import { JSDOM } from 'jsdom-napi-rs-canvas';
import { notFound } from 'next/navigation';
import { getBlogPostById } from '../../../database/blogPosts';
import Common from '../common';
Expand Down
24 changes: 20 additions & 4 deletions database/connect.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import 'server-only';
import { config } from 'dotenv-safe';
import postgres from 'postgres';

// This loads all environment variables from a .env file
// for all code after this line
Comment thread
karlhorky marked this conversation as resolved.
if (!process.env.FLY_IO) config();
// Making a simple connection to Postgres
// Next.js fast refresh increases database connection slot
// and causes connection slot error
// export const sql = postgres({
// transform: {
// ...postgres.camel,
// undefined: null,
// },
// });
Comment thread
karlhorky marked this conversation as resolved.
Outdated

if (!process.env.POSTGRES_URL) {
config();
}
Comment thread
karlhorky marked this conversation as resolved.
Outdated

// Type needed for the connection function below
declare module globalThis {
let postgresSqlClient: ReturnType<typeof postgres> | undefined;
}
Expand All @@ -15,12 +25,18 @@ declare module globalThis {
function connectOneTimeToDatabase() {
if (!globalThis.postgresSqlClient) {
globalThis.postgresSqlClient = postgres({
host: process.env.POSTGRES_HOST || process.env.PGHOST,
username: process.env.POSTGRES_USER || process.env.PGUSERNAME,
password: process.env.POSTGRES_PASSWORD || process.env.PGPASSWORD,
database: process.env.POSTGRES_DATABASE || process.env.PGDATABASE,
ssl: !!process.env.POSTGRES_URL,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use Boolean() here for expressiveness?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transform: {
...postgres.camel,
undefined: null,
},
});
}

return globalThis.postgresSqlClient;
}

Expand Down
16 changes: 0 additions & 16 deletions fly.toml

This file was deleted.

13 changes: 13 additions & 0 deletions ley.config.js
Comment thread
karlhorky marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const options = {};

if (process.env.POSTGRES_URL) {
options.ssl = true;

// Set standard environment variables
process.env.PGHOST = process.env.POSTGRES_HOST;
process.env.PGDATABASE = process.env.POSTGRES_DATABASE;
process.env.PGUSERNAME = process.env.POSTGRES_USER;
process.env.PGPASSWORD = process.env.POSTGRES_PASSWORD;
}

module.exports = options;
13 changes: 13 additions & 0 deletions ley.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const options = {};

if (process.env.POSTGRES_URL) {
options.ssl = true;

// Set standard environment variables
process.env.PGHOST = process.env.POSTGRES_HOST;
process.env.PGDATABASE = process.env.POSTGRES_DATABASE;
process.env.PGUSERNAME = process.env.POSTGRES_USER;
process.env.PGPASSWORD = process.env.POSTGRES_PASSWORD;
}

export default options;
14 changes: 13 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const nextConfig = {
reactStrictMode: true,
experimental: {
appDir: true,
serverComponentsExternalPackages: ['canvas', 'jsdom'],
serverComponentsExternalPackages: ['jsdom-napi-rs-canvas'],
typedRoutes: true,
},
eslint: {
Expand All @@ -14,4 +14,16 @@ const nextConfig = {
},
};

// For building on vercel: https://github.com/Automattic/node-canvas/issues/1779
if (
process.env.LD_LIBRARY_PATH == null ||
!process.env.LD_LIBRARY_PATH.includes(
`${process.env.PWD}/node_modules/canvas/build/Release:`,
)
) {
process.env.LD_LIBRARY_PATH = `${
process.env.PWD
}/node_modules/canvas/build/Release:${process.env.LD_LIBRARY_PATH || ''}`;
}

Comment thread
karlhorky marked this conversation as resolved.
Outdated
module.exports = nextConfig;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
"@types/cookie": "0.5.1",
"@types/dotenv-safe": "8.1.2",
"bcrypt": "5.1.0",
"canvas": "2.11.2",
"cookie": "0.5.0",
"dompurify": "3.0.3",
"dotenv-cli": "7.2.1",
"dotenv-safe": "8.2.0",
"jsdom": "22.1.0",
"jsdom-napi-rs-canvas": "^19.0.0",
"ley": "0.8.1",
"next": "13.4.7",
"postgres": "3.3.5",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-markdown": "8.0.7",
"sass": "1.63.6",
"server-only": "^0.0.1",
"sharp": "0.32.1",
"tsm": "2.3.0",
"zod": "3.21.4"
Expand Down
Loading