WIP: build attempted
This commit is contained in:
parent
a1cba242e9
commit
5c8a3f56dd
8
Dockerfile
Normal file
8
Dockerfile
Normal file
@ -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";
|
import {RowDataPacket} from "mysql2";
|
||||||
|
|
||||||
async function query() {
|
async function query() {
|
||||||
try {
|
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)
|
return(rows[0]['slug'] as string)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(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(
|
return(
|
||||||
<div className={`flex flex-col`}>
|
<div className={`flex flex-col`}>
|
||||||
<p>Env: { process.env.MYSQL_HOST }</p>
|
<p>Env: { process.env.MYSQL_HOST }</p>
|
||||||
<p>Result: { await query() }</p>
|
<p>Result: { await query() }</p>
|
||||||
|
<p>Flag: { flag }</p>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -1,19 +1,12 @@
|
|||||||
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 fs from 'fs';
|
||||||
import * as appEnv from "./env";
|
import * as appEnv from "./env";
|
||||||
|
|
||||||
if (typeof process.env.MYSQL_SSL_CA === 'undefined') {
|
let pool: Pool | undefined;
|
||||||
throw new Error("missing MYSQL_SSL_CA")
|
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")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
export function getPool(): Pool {
|
||||||
const access: PoolOptions = {
|
const access: PoolOptions = {
|
||||||
host: appEnv.getMysqlHost(),
|
host: appEnv.getMysqlHost(),
|
||||||
port: appEnv.getMysqlPort(),
|
port: appEnv.getMysqlPort(),
|
||||||
@ -34,6 +27,16 @@ const access: PoolOptions = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const pool = mysql.createPool(access)
|
if (typeof pool === 'undefined') {
|
||||||
|
pool = mysql.createPool(access)
|
||||||
|
}
|
||||||
|
|
||||||
export const promisePool = pool.promise()
|
return pool
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getPromisePool(): pPool {
|
||||||
|
if (typeof promisePool === 'undefined') {
|
||||||
|
promisePool = getPool().promise()
|
||||||
|
}
|
||||||
|
return promisePool
|
||||||
|
}
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
import { RowDataPacket } from "mysql2";
|
import { RowDataPacket } from "mysql2";
|
||||||
import { promisePool } from "@/backend/db";
|
import { getPromisePool } from "@/backend/db";
|
||||||
|
|
||||||
export async function getPost(slug: string): Promise<string> {
|
export async function getPost(slug: string): Promise<string> {
|
||||||
try {
|
try {
|
||||||
const [rows, fields] = await promisePool.query<RowDataPacket[]>(
|
const [rows, fields] = await getPromisePool().query<RowDataPacket[]>(
|
||||||
'select content from post where slug = ?', [slug])
|
'select content from post where slug = ?', [slug])
|
||||||
return rows[0]['content']
|
return rows[0]['content']
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
|
output: "standalone",
|
||||||
webpack: (config) => {
|
webpack: (config) => {
|
||||||
config.externals = [...config.externals, "jsdom"];
|
config.externals = [...config.externals, "jsdom"];
|
||||||
return config;
|
return config;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user