WIP: build attempted
This commit is contained in:
parent
a1cba242e9
commit
5c8a3f56dd
|
@ -0,0 +1,8 @@
|
|||
FROM node:lts-alpine as builder
|
||||
|
||||
USER 1000:1000
|
||||
ADD --chown=1000:1000 . /home/node/nextts
|
||||
WORKDIR /home/node/nextts
|
||||
RUN wget -qO- https://get.pnpm.io/install.sh | ENV="/home/node/.shrc" SHELL="$(which sh)" sh -
|
||||
ENV PATH=/home/node/.local/share/pnpm:$PATH
|
||||
RUN pnpm install && pnpm run build
|
|
@ -1,9 +1,9 @@
|
|||
import { promisePool } from "@/backend/db";
|
||||
import { getPromisePool } from "@/backend/db";
|
||||
import {RowDataPacket} from "mysql2";
|
||||
|
||||
async function query() {
|
||||
try {
|
||||
const [rows, fields] = await promisePool.query<RowDataPacket[]>('select slug from post limit 1;')
|
||||
const [rows, fields] = await getPromisePool().query<RowDataPacket[]>('select slug from post limit 1;')
|
||||
return(rows[0]['slug'] as string)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
|
@ -11,11 +11,18 @@ async function query() {
|
|||
}
|
||||
}
|
||||
|
||||
export default async function DbCheck() {
|
||||
export default async function DbCheck({ searchParams }: { searchParams: { [key: string]: string | string[] | undefined }}) {
|
||||
let flag = "empty";
|
||||
|
||||
if (typeof searchParams["flag"] === 'string') {
|
||||
flag = searchParams["flag"]
|
||||
}
|
||||
|
||||
return(
|
||||
<div className={`flex flex-col`}>
|
||||
<p>Env: { process.env.MYSQL_HOST }</p>
|
||||
<p>Result: { await query() }</p>
|
||||
<p>Flag: { flag }</p>
|
||||
</div>
|
||||
)
|
||||
}
|
|
@ -1,39 +1,42 @@
|
|||
import mysql, { PoolOptions } from "mysql2";
|
||||
import mysql, { PoolOptions, Pool } from "mysql2";
|
||||
import { Pool as pPool } from "mysql2/promise"
|
||||
import * as fs from 'fs';
|
||||
import * as appEnv from "./env";
|
||||
|
||||
if (typeof process.env.MYSQL_SSL_CA === 'undefined') {
|
||||
throw new Error("missing MYSQL_SSL_CA")
|
||||
}
|
||||
let pool: Pool | undefined;
|
||||
let promisePool: pPool | undefined;
|
||||
|
||||
if (typeof process.env.MYSQL_SSL_KEY === 'undefined') {
|
||||
throw new Error("missing MYSQL_SSL_KEY")
|
||||
}
|
||||
|
||||
if (typeof process.env.MYSQL_SSL_CERT === 'undefined') {
|
||||
throw new Error("missing MYSQL_SSL_CERT")
|
||||
}
|
||||
|
||||
const access: PoolOptions = {
|
||||
host: appEnv.getMysqlHost(),
|
||||
port: appEnv.getMysqlPort(),
|
||||
user: appEnv.getMysqlUser(),
|
||||
password: appEnv.getMysqlPassword(),
|
||||
database: appEnv.getMysqlDatabase(),
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
maxIdle: 10,
|
||||
idleTimeout: 60000,
|
||||
queueLimit: 0,
|
||||
enableKeepAlive: true,
|
||||
keepAliveInitialDelay: 0,
|
||||
ssl: {
|
||||
ca: fs.readFileSync(appEnv.getMysqlSslCaFile()),
|
||||
key: fs.readFileSync(appEnv.getMysqlSslKeyFile()),
|
||||
cert: fs.readFileSync(appEnv.getMysqlSslCertFile())
|
||||
export function getPool(): Pool {
|
||||
const access: PoolOptions = {
|
||||
host: appEnv.getMysqlHost(),
|
||||
port: appEnv.getMysqlPort(),
|
||||
user: appEnv.getMysqlUser(),
|
||||
password: appEnv.getMysqlPassword(),
|
||||
database: appEnv.getMysqlDatabase(),
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
maxIdle: 10,
|
||||
idleTimeout: 60000,
|
||||
queueLimit: 0,
|
||||
enableKeepAlive: true,
|
||||
keepAliveInitialDelay: 0,
|
||||
ssl: {
|
||||
ca: fs.readFileSync(appEnv.getMysqlSslCaFile()),
|
||||
key: fs.readFileSync(appEnv.getMysqlSslKeyFile()),
|
||||
cert: fs.readFileSync(appEnv.getMysqlSslCertFile())
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof pool === 'undefined') {
|
||||
pool = mysql.createPool(access)
|
||||
}
|
||||
|
||||
return pool
|
||||
}
|
||||
|
||||
export const pool = mysql.createPool(access)
|
||||
|
||||
export const promisePool = pool.promise()
|
||||
export function getPromisePool(): pPool {
|
||||
if (typeof promisePool === 'undefined') {
|
||||
promisePool = getPool().promise()
|
||||
}
|
||||
return promisePool
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { RowDataPacket } from "mysql2";
|
||||
import { promisePool } from "@/backend/db";
|
||||
import { getPromisePool } from "@/backend/db";
|
||||
|
||||
export async function getPost(slug: string): Promise<string> {
|
||||
try {
|
||||
const [rows, fields] = await promisePool.query<RowDataPacket[]>(
|
||||
const [rows, fields] = await getPromisePool().query<RowDataPacket[]>(
|
||||
'select content from post where slug = ?', [slug])
|
||||
return rows[0]['content']
|
||||
} catch (e) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
output: "standalone",
|
||||
webpack: (config) => {
|
||||
config.externals = [...config.externals, "jsdom"];
|
||||
return config;
|
||||
|
|
Loading…
Reference in New Issue