env and database access overhaul;
new dev scripts
This commit is contained in:
9
.env
9
.env
@ -6,15 +6,8 @@
|
|||||||
# Linux: `openssl rand -hex 32` or go to https://generate-secret.now.sh/32
|
# Linux: `openssl rand -hex 32` or go to https://generate-secret.now.sh/32
|
||||||
NEXTAUTH_SECRET=ed8a9681efc414df89dfd03cd188ed58
|
NEXTAUTH_SECRET=ed8a9681efc414df89dfd03cd188ed58
|
||||||
|
|
||||||
|
NODE_ENV=development
|
||||||
# mysql
|
# mysql
|
||||||
DATABASE_PROVIDER=mysql
|
|
||||||
# DATABASE_URL=mysql://cart:cart2023@192.168.0.10:3306/cart_dev
|
|
||||||
# DATABASE_URL=mysql://root:Zelen0ku4e@192.168.0.10:3306/cart_dev
|
|
||||||
# DATABASE_URL=mysql://cart:cartpw@20.101.62.76:3307/cart
|
|
||||||
|
|
||||||
DATABASE_URL="mysql://root:mdp-11000@127.0.0.1:3306/cart"
|
|
||||||
|
|
||||||
# DATABASE_URL=mysql://cart:cartpw@localhost:3306/cart # npx prisma migrate dev
|
|
||||||
|
|
||||||
# // owner: dobromir.popov@gmail.com | Специално Свидетелстване София
|
# // owner: dobromir.popov@gmail.com | Специално Свидетелстване София
|
||||||
# // https://console.cloud.google.com/apis/credentials/oauthclient/926212607479-d3m8hm8f8esp3rf1639prskn445sa01v.apps.googleusercontent.com?project=grand-forge-108716
|
# // https://console.cloud.google.com/apis/credentials/oauthclient/926212607479-d3m8hm8f8esp3rf1639prskn445sa01v.apps.googleusercontent.com?project=grand-forge-108716
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
NODE_TLS_REJECT_UNAUTHORIZED=0
|
NODE_TLS_REJECT_UNAUTHORIZED=0
|
||||||
# NODE_EXTRA_CA_CERTS=C:\\Users\\popov\\AppData\\Local\\mkcert
|
# NODE_EXTRA_CA_CERTS=C:\\Users\\popov\\AppData\\Local\\mkcert
|
||||||
PROTOCOL=http
|
PROTOCOL=https
|
||||||
PORT=3003
|
PORT=3003
|
||||||
HOST=localhost
|
HOST=localhost
|
||||||
NEXT_PUBLIC_PUBLIC_URL=https://localhost:3003
|
NEXT_PUBLIC_PUBLIC_URL=https://localhost:3003
|
||||||
DATABASE_URL=mysql://root:Zelen0ku4e@192.168.0.10:3306/cart_dev
|
DATABASE=mysql://cart:cartpw@192.168.0.10:3306/cart_dev
|
||||||
|
#DATABASE=mysql://cart:cartpw@localhost:3306/cart
|
||||||
|
|
||||||
SSL_KEY=./certificates/localhost-key.pem
|
SSL_KEY=./certificates/localhost-key.pem
|
||||||
SSL_CERT=./certificates/localhost.pem
|
SSL_CERT=./certificates/localhost.pem
|
||||||
|
@ -4,7 +4,7 @@ PROTOCOL=http
|
|||||||
PORT=3003
|
PORT=3003
|
||||||
HOST=localhost
|
HOST=localhost
|
||||||
NEXT_PUBLIC_PUBLIC_URL=http://localhost:3003
|
NEXT_PUBLIC_PUBLIC_URL=http://localhost:3003
|
||||||
DATABASE_URL="mysql://root:mdp-11000@127.0.0.1:3306/cart?connection_limit=5&charset=utf8mb4&collation=utf8mb4_unicode_ci"
|
DATABASE="mysql://root:mdp-11000@127.0.0.1:3306/cart?connection_limit=5&charset=utf8mb4&collation=utf8mb4_unicode_ci"
|
||||||
|
|
||||||
SSL_KEY=./certificates/localhost-key.pem
|
SSL_KEY=./certificates/localhost-key.pem
|
||||||
SSL_CERT=./certificates/localhost.pem
|
SSL_CERT=./certificates/localhost.pem
|
||||||
|
@ -6,4 +6,4 @@ NEXT_PUBLIC_PUBLIC_URL= https://sofia.mwitnessing.com
|
|||||||
# Linux: `openssl rand -hex 32` or go to https://generate-secret.now.sh/32
|
# Linux: `openssl rand -hex 32` or go to https://generate-secret.now.sh/32
|
||||||
NEXTAUTH_SECRET=1dd8a5457970d1dda50600be28e935ecc4513ff27c49c431849e6746f158d638
|
NEXTAUTH_SECRET=1dd8a5457970d1dda50600be28e935ecc4513ff27c49c431849e6746f158d638
|
||||||
# ? do we need to duplicate this? already defined in the deoployment yml file
|
# ? do we need to duplicate this? already defined in the deoployment yml file
|
||||||
DATABASE_URL=mysql://jwpwsofia:dwxhns9p9vp248V39xJyRthUsZ2gR9@mariadb:3306/jwpwsofia
|
DATABASE=mysql://jwpwsofia:dwxhns9p9vp248V39xJyRthUsZ2gR9@mariadb:3306/jwpwsofia
|
@ -6,7 +6,7 @@ NEXT_PUBLIC_PUBLIC_URL=https://staging.mwitnessing.com
|
|||||||
# Linux: `openssl rand -hex 32` or go to https://generate-secret.now.sh/32
|
# Linux: `openssl rand -hex 32` or go to https://generate-secret.now.sh/32
|
||||||
NEXTAUTH_SECRET=1dd8a5457970d1dda50600be28e935ecc4513ff27c49c431849e6746f158d638
|
NEXTAUTH_SECRET=1dd8a5457970d1dda50600be28e935ecc4513ff27c49c431849e6746f158d638
|
||||||
# ? do we need to duplicate this? already defined in the deoployment yml file
|
# ? do we need to duplicate this? already defined in the deoployment yml file
|
||||||
DATABASE_URL=mysql://jwpwsofia_demo:dwxhns9p9vp248@mariadb:3306/jwpwsofia_demo
|
DATABASE=mysql://jwpwsofia_demo:dwxhns9p9vp248@mariadb:3306/jwpwsofia_demo
|
||||||
|
|
||||||
APPLE_ID=
|
APPLE_ID=
|
||||||
APPLE_TEAM_ID=
|
APPLE_TEAM_ID=
|
||||||
|
14
.vscode/launch.json
vendored
14
.vscode/launch.json
vendored
@ -5,13 +5,23 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "Run npm nodemon (DEV)",
|
"name": "Run npm nodemon (DB)",
|
||||||
"command": "npm run debug",
|
"command": "npm run debug",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "node-terminal",
|
"type": "node-terminal",
|
||||||
"preLaunchTask": "killInspector",
|
"preLaunchTask": "killInspector",
|
||||||
"env": {
|
"env": {
|
||||||
"NODE_ENV": "development"
|
"APP_ENV": "development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Run npm nodemon (Raph)",
|
||||||
|
"command": "npm run debug",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "node-terminal",
|
||||||
|
"preLaunchTask": "killInspector",
|
||||||
|
"env": {
|
||||||
|
"APP_ENV": "development.raph"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -10,7 +10,7 @@ services:
|
|||||||
- /mnt/apps/docker_volumes/cart/app/next-cart-app:/app
|
- /mnt/apps/docker_volumes/cart/app/next-cart-app:/app
|
||||||
environment:
|
environment:
|
||||||
- NODE_ENV=demo
|
- NODE_ENV=demo
|
||||||
- DATABASE_URL=mysql://cart:cart2023@192.168.0.10:3306/cart
|
- DATABASE=mysql://cart:cart2023@192.168.0.10:3306/cart
|
||||||
#command: sh -c "apk update && apk add git && rm -rf /tmp/clone && git clone https://git.d-popov.com/popov/next-cart-app.git /tmp/clone && rm -rf /app/* && cp -R /tmp/clone/next-cart-app/* /app/ && rm -rf /tmp/clone && npm cache clean --force && rm -rf /app/node_modules /app/package-lock.json && npm --silent --prefix /app install /app && npx --prefix /app prisma generate && npm --prefix /app run test; tail -f /dev/null"
|
#command: sh -c "apk update && apk add git && rm -rf /tmp/clone && git clone https://git.d-popov.com/popov/next-cart-app.git /tmp/clone && rm -rf /app/* && cp -R /tmp/clone/next-cart-app/* /app/ && rm -rf /tmp/clone && npm cache clean --force && rm -rf /app/node_modules /app/package-lock.json && npm --silent --prefix /app install /app && npx --prefix /app prisma generate && npm --prefix /app run test; tail -f /dev/null"
|
||||||
#command: sh -c "rm -rf /tmp/clone && git clone https://git.d-popov.com/popov/next-cart-app.git /tmp/clone && rm -rf /app/* && cp -R /tmp/clone/next-cart-app/* /app/ && rm -rf /tmp/clone && npm cache clean --force && rm -rf /app/node_modules /app/package-lock.json && npm --silent --prefix /app install /app && npx --prefix /app prisma generate && npm --prefix /app run test; tail -f /dev/null"
|
#command: sh -c "rm -rf /tmp/clone && git clone https://git.d-popov.com/popov/next-cart-app.git /tmp/clone && rm -rf /app/* && cp -R /tmp/clone/next-cart-app/* /app/ && rm -rf /tmp/clone && npm cache clean --force && rm -rf /app/node_modules /app/package-lock.json && npm --silent --prefix /app install /app && npx --prefix /app prisma generate && npm --prefix /app run test; tail -f /dev/null"
|
||||||
command: sh -c "npm cache clean --force && rm -rf /app/node_modules /app/package-lock.json && npm --silent --prefix /app install /app && npx --prefix /app prisma generate && npm --prefix /app run test; tail -f /dev/null"
|
command: sh -c "npm cache clean --force && rm -rf /app/node_modules /app/package-lock.json && npm --silent --prefix /app install /app && npx --prefix /app prisma generate && npm --prefix /app run test; tail -f /dev/null"
|
||||||
|
@ -8,7 +8,7 @@ services:
|
|||||||
- /mnt/apps/DEV/cart-demo:/app
|
- /mnt/apps/DEV/cart-demo:/app
|
||||||
environment:
|
environment:
|
||||||
- NODE_ENV=demo
|
- NODE_ENV=demo
|
||||||
- DATABASE_URL=mysql://cart:cart2023@192.168.0.10:3306/cart
|
- DATABASE=mysql://cart:cart2023@192.168.0.10:3306/cart
|
||||||
command: sh -c " cd /app && npm run test; tail -f /dev/null"
|
command: sh -c " cd /app && npm run test; tail -f /dev/null"
|
||||||
tty: true
|
tty: true
|
||||||
stdin_open: true
|
stdin_open: true
|
||||||
|
@ -8,7 +8,7 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- NODE_ENV=demo
|
- NODE_ENV=demo
|
||||||
- TZ=Europe/Sofia
|
- TZ=Europe/Sofia
|
||||||
- DATABASE_URL=mysql://jwpwsofia_demo:dwxhns9p9vp248@jwpwsofia:3306/jwpwsofia_demo
|
- DATABASE=mysql://jwpwsofia_demo:dwxhns9p9vp248@jwpwsofia:3306/jwpwsofia_demo
|
||||||
- UPDATE_CODE_FROM_GIT=true # Set to true to pull latest code from Git
|
- UPDATE_CODE_FROM_GIT=true # Set to true to pull latest code from Git
|
||||||
- GIT_BRANCH=main
|
- GIT_BRANCH=main
|
||||||
- GIT_USERNAME=deploy
|
- GIT_USERNAME=deploy
|
||||||
|
@ -12,8 +12,8 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- NODE_ENV=production
|
- NODE_ENV=production
|
||||||
- TZ=Europe/Sofia
|
- TZ=Europe/Sofia
|
||||||
- DATABASE_URL=mysql://jwpwsofia:dwxhns9p9vp248V39xJyRthUsZ2gR9@mariadb:3306/jwpwsofia
|
- DATABASE=mysql://jwpwsofia:dwxhns9p9vp248V39xJyRthUsZ2gR9@mariadb:3306/jwpwsofia
|
||||||
#- DATABASE_URL=postgres://jwpwsofia:dwxhns9p9vp248V39xJyRthUsZ2gR9@mariadb:3306/jwpwsofia
|
#- DATABASE=postgres://jwpwsofia:dwxhns9p9vp248V39xJyRthUsZ2gR9@mariadb:3306/jwpwsofia
|
||||||
- UPDATE_CODE_FROM_GIT=true # Set to true to pull latest code from Git
|
- UPDATE_CODE_FROM_GIT=true # Set to true to pull latest code from Git
|
||||||
- GIT_BRANCH=production
|
- GIT_BRANCH=production
|
||||||
- GIT_USERNAME=deploy
|
- GIT_USERNAME=deploy
|
||||||
|
@ -6,7 +6,7 @@ services:
|
|||||||
- "5001:3000"
|
- "5001:3000"
|
||||||
environment:
|
environment:
|
||||||
- NODE_ENV=prod
|
- NODE_ENV=prod
|
||||||
- DATABASE_URL=mysql://cart:o74x642Rc8@mariadb:3306/cart
|
- DATABASE=mysql://cart:o74x642Rc8@mariadb:3306/cart
|
||||||
- UPDATE_CODE_FROM_GIT=true # Set to true to pull latest code from Git
|
- UPDATE_CODE_FROM_GIT=true # Set to true to pull latest code from Git
|
||||||
- GIT_USERNAME=deploy
|
- GIT_USERNAME=deploy
|
||||||
- GIT_PASSWORD=%L3Kr2R438u4F7^%40
|
- GIT_PASSWORD=%L3Kr2R438u4F7^%40
|
||||||
|
@ -40,7 +40,7 @@ services:
|
|||||||
- /mnt/data/apps/docker_volumes/cart/app:/app
|
- /mnt/data/apps/docker_volumes/cart/app:/app
|
||||||
environment:
|
environment:
|
||||||
- NODE_ENV=demo
|
- NODE_ENV=demo
|
||||||
- DATABASE_URL=mysql://cart:cartpw2024@mariadb:3306/cart
|
- DATABASE=mysql://cart:cartpw2024@mariadb:3306/cart
|
||||||
#! entrypoint: ["/bin/sh", "/entrypoint.sh"]
|
#! entrypoint: ["/bin/sh", "/entrypoint.sh"]
|
||||||
#run: npm install && npx prisma generate && npm run test;
|
#run: npm install && npx prisma generate && npm run test;
|
||||||
# command: "npx prisma migrate deploy && npx prisma migrate deploy && npm run build && npm run start"
|
# command: "npx prisma migrate deploy && npx prisma migrate deploy && npm run build && npm run start"
|
||||||
|
@ -111,6 +111,11 @@ export OPENAI_API_KEY=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 # dev-
|
|||||||
|
|
||||||
# ----------------------------------------------update PRISMA schema/sync database ----------------------------------------------- #
|
# ----------------------------------------------update PRISMA schema/sync database ----------------------------------------------- #
|
||||||
# prisma migrate dev --create-only
|
# prisma migrate dev --create-only
|
||||||
|
NODE_ENV=production npx prisma migrate deploy
|
||||||
|
#windows
|
||||||
|
$env:DATABASE="mysql://cart:cartpw@localhost:3306/cart"; npx prisma migrate deploy
|
||||||
|
$env:DATABASE="mysql://cart:cartpw@192.168.0.10:3306/cart_dev"; npx prisma migrate deploy
|
||||||
|
|
||||||
npx prisma generate
|
npx prisma generate
|
||||||
npx prisma migrate dev --name fix_nextauth_schema --create-only
|
npx prisma migrate dev --name fix_nextauth_schema --create-only
|
||||||
>Prisma Migrate created the following migration without applying it 20231214163235_fix_nextauth_schema
|
>Prisma Migrate created the following migration without applying it 20231214163235_fix_nextauth_schema
|
||||||
@ -196,3 +201,8 @@ ncu -u
|
|||||||
|
|
||||||
enable apple ID:
|
enable apple ID:
|
||||||
curl https://gist.githubusercontent.com/balazsorban44/09613175e7b37ec03f676dcefb7be5eb/raw/b0d31aa0c7f58e0088fdf59ec30cad1415a3475b/apple-gen-secret.mjs -o apple-gen-secret.mjs
|
curl https://gist.githubusercontent.com/balazsorban44/09613175e7b37ec03f676dcefb7be5eb/raw/b0d31aa0c7f58e0088fdf59ec30cad1415a3475b/apple-gen-secret.mjs -o apple-gen-secret.mjs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Project setup:
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://git.d-popov.com/popov/next-cart-app",
|
"homepage": "https://git.d-popov.com/popov/next-cart-app",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"debug": "nodemon --inspect server.js",
|
"debug": "node server.js",
|
||||||
"debug-env-dev": "dotenv -e .env.development -- nodemon --inspect server.js",
|
"debug-env": "dotenv -e .env.$APP_ENV -- nodemon --inspect server.js",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"buildWin": "npm run build",
|
"buildWin": "npm run build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
|
2
prisma/administrative_scripts/create_user.sql
Normal file
2
prisma/administrative_scripts/create_user.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
CREATE USER 'cart'@'%' IDENTIFIED BY 'cartpw';
|
||||||
|
GRANT ALL PRIVILEGES ON `cart\_dev`.* TO 'cart'@'%' WITH GRANT OPTION;
|
@ -10,7 +10,6 @@
|
|||||||
// //to generate schema
|
// //to generate schema
|
||||||
// > npx prisma
|
// > npx prisma
|
||||||
|
|
||||||
// GPT
|
|
||||||
// This is a Prisma database schema definition, which describes the structure and relationships between various entities in the database. Here's a brief overview of the different models:
|
// This is a Prisma database schema definition, which describes the structure and relationships between various entities in the database. Here's a brief overview of the different models:
|
||||||
|
|
||||||
// Publisher: Represents a publisher, with attributes such as first name, last name, email, phone, age, and availability. A publisher can have many availabilities and assignments, and can also have multiple user accounts and sessions.
|
// Publisher: Represents a publisher, with attributes such as first name, last name, email, phone, age, and availability. A publisher can have many availabilities and assignments, and can also have multiple user accounts and sessions.
|
||||||
@ -21,9 +20,10 @@
|
|||||||
// Location: Represents a location where a cart event can take place. A location can have a name, address, and multiple cart events.
|
// Location: Represents a location where a cart event can take place. A location can have a name, address, and multiple cart events.
|
||||||
// Overall, this schema seems to represent a system for managing publishers and their assignments to cart events, including their availabilities and locations.
|
// Overall, this schema seems to represent a system for managing publishers and their assignments to cart events, including their availabilities and locations.
|
||||||
|
|
||||||
|
//$env:DATABASE="{connection string}"; npx prisma migrate deploy
|
||||||
datasource db {
|
datasource db {
|
||||||
provider = "mysql"
|
provider = "mysql"
|
||||||
url = env("DATABASE_URL")
|
url = env("DATABASE")
|
||||||
}
|
}
|
||||||
|
|
||||||
generator client {
|
generator client {
|
||||||
|
18
server.js
18
server.js
@ -20,22 +20,9 @@ process.env.TZ = 'Europe/Sofia';
|
|||||||
// Global variable to store the base URL
|
// Global variable to store the base URL
|
||||||
let baseUrlGlobal;
|
let baseUrlGlobal;
|
||||||
|
|
||||||
// if (process.env.NODE_ENV === 'test') {
|
console.log("initial process.env.APP_ENV = ", process.env.APP_ENV);
|
||||||
// // Load environment variables from .env.test
|
|
||||||
// require('dotenv').config({ path: '.env.test' });
|
|
||||||
// } else {
|
|
||||||
// // Load default environment variables
|
|
||||||
// require('dotenv').config();
|
|
||||||
// }
|
|
||||||
|
|
||||||
console.log("initial process.env.NODE_ENV = ", process.env.NODE_ENV); //NODE_ENV can be passed as docker param
|
console.log("initial process.env.NODE_ENV = ", process.env.NODE_ENV); //NODE_ENV can be passed as docker param
|
||||||
// require('dotenv').config({
|
require('dotenv').config({ path: `.env.${process.env.APP_ENV}` });
|
||||||
// path: `.env.${process.env.NODE_ENV}`
|
|
||||||
// });
|
|
||||||
require('dotenv').config(); // Fallback to default
|
|
||||||
require('dotenv').config({ path: `.env.${process.env.NODE_ENV}` }); // Environment-specific
|
|
||||||
|
|
||||||
|
|
||||||
console.log("process.env.NODE_ENV = ", process.env.NODE_ENV);
|
console.log("process.env.NODE_ENV = ", process.env.NODE_ENV);
|
||||||
|
|
||||||
const PROTOCOL = process.env.PROTOCOL;
|
const PROTOCOL = process.env.PROTOCOL;
|
||||||
@ -52,6 +39,7 @@ console.log("process.env.NEXTAUTH_URL = ", process.env.NEXTAUTH_URL);
|
|||||||
console.log("process.env.PORT = ", process.env.PORT);
|
console.log("process.env.PORT = ", process.env.PORT);
|
||||||
console.log("process.env.TELEGRAM_BOT = ", process.env.TELEGRAM_BOT);
|
console.log("process.env.TELEGRAM_BOT = ", process.env.TELEGRAM_BOT);
|
||||||
console.log("process.env.DATABASE_URL = ", process.env.DATABASE_URL);
|
console.log("process.env.DATABASE_URL = ", process.env.DATABASE_URL);
|
||||||
|
console.log("process.env.DATABASE = ", process.env.DATABASE);
|
||||||
|
|
||||||
//require('module-alias/register');
|
//require('module-alias/register');
|
||||||
|
|
||||||
|
@ -83,14 +83,14 @@ exports.getBaseUrl = function (relative = "", req = null) {
|
|||||||
let prisma;
|
let prisma;
|
||||||
exports.getPrismaClient = function getPrismaClient() {
|
exports.getPrismaClient = function getPrismaClient() {
|
||||||
if (!prisma) {
|
if (!prisma) {
|
||||||
logger.debug("getPrismaClient: process.env.DATABASE_URL = ", process.env.DATABASE_URL);
|
logger.debug("getPrismaClient: process.env.DATABASE = ", process.env.DATABASE);
|
||||||
prisma = new PrismaClient({
|
prisma = new PrismaClient({
|
||||||
// Optional: Enable logging
|
// Optional: Enable logging
|
||||||
//log: ['query', 'info', 'warn', 'error'],
|
//log: ['query', 'info', 'warn', 'error'],
|
||||||
datasources: { db: { url: process.env.DATABASE_URL } },
|
datasources: { db: { url: process.env.DATABASE } },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
logger.debug("getPrismaClient: process.env.DATABASE_URL = ", process.env.DATABASE_URL);
|
logger.debug("getPrismaClient: process.env.DATABASE = ", process.env.DATABASE);
|
||||||
|
|
||||||
return prisma;
|
return prisma;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user