mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-09 23:48:36 +01:00
add cors + adjusting dockerfile
This commit is contained in:
@@ -1,8 +1,15 @@
|
|||||||
|
shared/node_modules
|
||||||
|
shared/.output
|
||||||
|
|
||||||
|
lyx-ui/node_modules
|
||||||
|
lyx-ui/.nuxt
|
||||||
|
lyx-ui/.output
|
||||||
|
|
||||||
|
dashboard/node_modules
|
||||||
|
dashboard/.nuxt
|
||||||
|
dashboard/.output
|
||||||
|
dashboard/explains
|
||||||
|
dashboard/tests
|
||||||
|
dashboard/.env
|
||||||
|
dashboard/winston-*.ndjson
|
||||||
|
|
||||||
# Consumer
|
|
||||||
**/node_modules
|
|
||||||
**/ecosystem.config.cjs
|
|
||||||
**/ecosystem.config.example.cjs
|
|
||||||
**/dist
|
|
||||||
**/.nuxt
|
|
||||||
**/.env
|
|
||||||
@@ -3,6 +3,7 @@ FROM node:21-alpine as base
|
|||||||
FROM base as build
|
FROM base as build
|
||||||
|
|
||||||
RUN npm i -g pnpm
|
RUN npm i -g pnpm
|
||||||
|
RUN npm i -g pm2
|
||||||
|
|
||||||
# COPY --link dashboard/package.json dashboard/pnpm-lock.yaml ./
|
# COPY --link dashboard/package.json dashboard/pnpm-lock.yaml ./
|
||||||
# RUN npm install --production=false
|
# RUN npm install --production=false
|
||||||
@@ -15,14 +16,15 @@ COPY --link consumer ./consumer
|
|||||||
COPY --link producer ./producer
|
COPY --link producer ./producer
|
||||||
COPY --link shared ./shared
|
COPY --link shared ./shared
|
||||||
|
|
||||||
WORKDIR /home/app/dashboard
|
WORKDIR /home/app/producer
|
||||||
RUN pnpm install
|
RUN pnpm install
|
||||||
|
|
||||||
WORKDIR /home/app/consumer
|
WORKDIR /home/app/consumer
|
||||||
RUN pnpm install
|
RUN pnpm install
|
||||||
|
|
||||||
WORKDIR /home/app/producer
|
WORKDIR /home/app/dashboard
|
||||||
RUN pnpm install
|
RUN pnpm install
|
||||||
|
RUN pnpm run dev
|
||||||
|
|
||||||
|
|
||||||
# CMD [ "node", "/home/app/.output/server/index.mjs" ]
|
# CMD [ "node", "/home/app/.output/server/index.mjs" ]
|
||||||
49
dashboard/Dockerfile
Normal file
49
dashboard/Dockerfile
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
# Start with a minimal Node.js base image
|
||||||
|
FROM node:21-alpine AS base
|
||||||
|
|
||||||
|
# Create a distinct build environment
|
||||||
|
FROM base AS build
|
||||||
|
|
||||||
|
# Install pnpm globally with caching to avoid reinstalling if nothing has changed
|
||||||
|
RUN npm i -g pnpm
|
||||||
|
|
||||||
|
# Set the working directory
|
||||||
|
WORKDIR /home/app
|
||||||
|
|
||||||
|
# Copy only package-related files to leverage caching
|
||||||
|
COPY --link ./dashboard/package.json ./dashboard/pnpm-lock.yaml ./dashboard/
|
||||||
|
COPY --link ./lyx-ui/package.json ./lyx-ui/pnpm-lock.yaml ./lyx-ui/
|
||||||
|
COPY --link ./shared/package.json ./shared/pnpm-lock.yaml ./shared/
|
||||||
|
|
||||||
|
# Install dependencies for each package
|
||||||
|
WORKDIR /home/app/lyx-ui
|
||||||
|
RUN pnpm install --frozen-lockfile
|
||||||
|
|
||||||
|
# WORKDIR /home/app/shared
|
||||||
|
# RUN pnpm install --frozen-lockfile
|
||||||
|
|
||||||
|
WORKDIR /home/app/dashboard
|
||||||
|
RUN pnpm install --frozen-lockfile
|
||||||
|
|
||||||
|
# Now copy the rest of the source files
|
||||||
|
WORKDIR /home/app
|
||||||
|
|
||||||
|
COPY --link ./dashboard ./dashboard
|
||||||
|
COPY --link ./lyx-ui ./lyx-ui
|
||||||
|
COPY --link ./shared ./shared
|
||||||
|
|
||||||
|
# Build the dashboard
|
||||||
|
WORKDIR /home/app/dashboard
|
||||||
|
RUN pnpm run build
|
||||||
|
|
||||||
|
# Use a smaller base image for the final production build
|
||||||
|
FROM node:21-alpine AS production
|
||||||
|
|
||||||
|
# Set the working directory for the production container
|
||||||
|
WORKDIR /home/app
|
||||||
|
|
||||||
|
# Copy the built application from the build stage
|
||||||
|
COPY --from=build /home/app/dashboard/.output /home/app/.output
|
||||||
|
|
||||||
|
# Start the application
|
||||||
|
CMD ["node", "/home/app/.output/server/index.mjs"]
|
||||||
@@ -10,7 +10,8 @@
|
|||||||
"postinstall": "nuxt prepare",
|
"postinstall": "nuxt prepare",
|
||||||
"test": "vitest",
|
"test": "vitest",
|
||||||
"docker-build": "docker build -t litlyx-dashboard -f Dockerfile ../",
|
"docker-build": "docker build -t litlyx-dashboard -f Dockerfile ../",
|
||||||
"docker-inspect": "docker run -it litlyx-dashboard sh"
|
"docker-inspect": "docker run -it litlyx-dashboard sh",
|
||||||
|
"docker-run": "docker run -p 3000:3000 --name litlyx-dashboard litlyx-dashboard"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@getbrevo/brevo": "^2.2.0",
|
"@getbrevo/brevo": "^2.2.0",
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
|
|
||||||
import { checkApiKey, checkAuthorization, eventsListApi } from '~/server/services/ApiService';
|
import { checkApiKey, checkAuthorization, eventsListApi } from '~/server/services/ApiService';
|
||||||
|
import { useCors } from '~/server/utils/useCors';
|
||||||
|
|
||||||
|
|
||||||
export default defineEventHandler(async event => {
|
export default defineEventHandler(async event => {
|
||||||
|
|
||||||
|
useCors(event);
|
||||||
|
|
||||||
const { rows, from, to, limit } = await readBody(event);
|
const { rows, from, to, limit } = await readBody(event);
|
||||||
|
|
||||||
const token = checkAuthorization(event);
|
const token = checkAuthorization(event);
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
|
|
||||||
import { checkApiKey, checkAuthorization, eventsListApi, } from '~/server/services/ApiService';
|
import { checkApiKey, checkAuthorization, eventsListApi, } from '~/server/services/ApiService';
|
||||||
|
import { useCors } from '~/server/utils/useCors';
|
||||||
|
|
||||||
|
|
||||||
export default defineEventHandler(async event => {
|
export default defineEventHandler(async event => {
|
||||||
|
|
||||||
|
useCors(event);
|
||||||
|
|
||||||
const { row, from, to, limit } = getQuery(event);
|
const { row, from, to, limit } = getQuery(event);
|
||||||
|
|
||||||
const token = checkAuthorization(event);
|
const token = checkAuthorization(event);
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
|
|
||||||
import { checkApiKey, checkAuthorization } from '~/server/services/ApiService';
|
import { checkApiKey, checkAuthorization } from '~/server/services/ApiService';
|
||||||
import { visitsListApi } from '../../services/ApiService';
|
import { visitsListApi } from '../../services/ApiService';
|
||||||
|
import { useCors } from '~/server/utils/useCors';
|
||||||
|
|
||||||
|
|
||||||
export default defineEventHandler(async event => {
|
export default defineEventHandler(async event => {
|
||||||
|
|
||||||
|
useCors(event);
|
||||||
|
|
||||||
const { rows, from, to, limit } = await readBody(event);
|
const { rows, from, to, limit } = await readBody(event);
|
||||||
|
|
||||||
const token = checkAuthorization(event);
|
const token = checkAuthorization(event);
|
||||||
|
|||||||
@@ -2,9 +2,12 @@
|
|||||||
import { ApiSettingsModel } from '@schema/ApiSettingsSchema';
|
import { ApiSettingsModel } from '@schema/ApiSettingsSchema';
|
||||||
import { VisitModel } from '@schema/metrics/VisitSchema';
|
import { VisitModel } from '@schema/metrics/VisitSchema';
|
||||||
import { checkApiKey, checkAuthorization, visitsListApi } from '~/server/services/ApiService';
|
import { checkApiKey, checkAuthorization, visitsListApi } from '~/server/services/ApiService';
|
||||||
|
import { useCors } from '~/server/utils/useCors';
|
||||||
|
|
||||||
export default defineEventHandler(async event => {
|
export default defineEventHandler(async event => {
|
||||||
|
|
||||||
|
useCors(event);
|
||||||
|
|
||||||
const { row, from, to, limit } = getQuery(event);
|
const { row, from, to, limit } = getQuery(event);
|
||||||
|
|
||||||
const token = checkAuthorization(event);
|
const token = checkAuthorization(event);
|
||||||
|
|||||||
10
dashboard/server/utils/useCors.ts
Normal file
10
dashboard/server/utils/useCors.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
|
||||||
|
import type { H3Event, EventHandlerRequest } from 'h3';
|
||||||
|
|
||||||
|
|
||||||
|
export function useCors(event: H3Event<EventHandlerRequest>) {
|
||||||
|
setResponseHeader(event, 'Access-Control-Allow-Origin', '*');
|
||||||
|
setResponseHeader(event, 'Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, DELETE');
|
||||||
|
setResponseHeader(event, 'Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
||||||
|
}
|
||||||
@@ -4,53 +4,60 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
MONGO_INITDB_ROOT_USERNAME: litlyx
|
MONGO_INITDB_ROOT_USERNAME: litlyx
|
||||||
MONGO_INITDB_ROOT_PASSWORD: litlyx
|
MONGO_INITDB_ROOT_PASSWORD: litlyx
|
||||||
ports:
|
|
||||||
- 27017:27017
|
# Uncomment to expose database
|
||||||
|
|
||||||
|
# ports:
|
||||||
|
# - 27017:27017
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
- mongo-data:/data/db
|
- mongo-data:/data/db
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
image: redis:alpine
|
image: redis:alpine
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
|
||||||
- "6379:6379"
|
# Uncomment to expose redis
|
||||||
|
|
||||||
|
# ports:
|
||||||
|
# - "6379:6379"
|
||||||
|
|
||||||
command: redis-server --save 20 1 --loglevel warning --requirepass litlyx
|
command: redis-server --save 20 1 --loglevel warning --requirepass litlyx
|
||||||
|
|
||||||
producer:
|
# producer:
|
||||||
image: litlyx-producer
|
# image: litlyx-producer
|
||||||
restart: always
|
# restart: always
|
||||||
ports:
|
# ports:
|
||||||
- "3099:3099"
|
# - "3099:3099"
|
||||||
environment:
|
# environment:
|
||||||
PORT: "3099"
|
# PORT: "3099"
|
||||||
REDIS_URL: "redis://cache"
|
# REDIS_URL: "redis://cache"
|
||||||
REDIS_USERNAME: "default"
|
# REDIS_USERNAME: "default"
|
||||||
REDIS_PASSWORD: "litlyx"
|
# REDIS_PASSWORD: "litlyx"
|
||||||
STREAM_NAME: "lib-events"
|
# STREAM_NAME: "lib-events"
|
||||||
build:
|
# build:
|
||||||
dockerfile: ./producer/Dockerfile
|
# dockerfile: ./producer/Dockerfile
|
||||||
|
|
||||||
|
# broker:
|
||||||
|
# image: litlyx-consumer
|
||||||
|
# restart: always
|
||||||
|
# ports:
|
||||||
|
# - "3999:3999"
|
||||||
|
# environment:
|
||||||
|
|
||||||
broker:
|
# # Optional - Used to send welcome and quota emails
|
||||||
image: litlyx-consumer
|
|
||||||
restart: always
|
|
||||||
ports:
|
|
||||||
- "3999:3999"
|
|
||||||
environment:
|
|
||||||
|
|
||||||
# Optional - Used to send welcome and quota emails
|
# # NUXT_EMAIL_SERVICE: "Brevo"
|
||||||
|
# # NUXT_BREVO_API_KEY: ""
|
||||||
|
|
||||||
# NUXT_EMAIL_SERVICE: "Brevo"
|
# PORT: "3999"
|
||||||
# NUXT_BREVO_API_KEY: ""
|
# MONGO_CONNECTION_STRING: "mongodb://litlyx:litlyx@mongo:27017/SimpleMetrics?readPreference=primaryPreferred&authSource=admin"
|
||||||
|
# REDIS_URL: "redis://cache"
|
||||||
PORT: "3999"
|
# REDIS_USERNAME: "default"
|
||||||
MONGO_CONNECTION_STRING: "mongodb://litlyx:litlyx@mongo:27017/SimpleMetrics?readPreference=primaryPreferred&authSource=admin"
|
# REDIS_PASSWORD: "litlyx"
|
||||||
REDIS_URL: "redis://cache"
|
# STREAM_NAME: "lib-events"
|
||||||
REDIS_USERNAME: "default"
|
# build:
|
||||||
REDIS_PASSWORD: "litlyx"
|
# dockerfile: ./broker/Dockerfile
|
||||||
STREAM_NAME: "lib-events"
|
|
||||||
build:
|
|
||||||
dockerfile: ./broker/Dockerfile
|
|
||||||
|
|
||||||
dashboard:
|
dashboard:
|
||||||
image: litlyx-dashboard
|
image: litlyx-dashboard
|
||||||
@@ -65,8 +72,7 @@ services:
|
|||||||
NUXT_REDIS_USERNAME: "default"
|
NUXT_REDIS_USERNAME: "default"
|
||||||
NUXT_REDIS_PASSWORD: "litlyx"
|
NUXT_REDIS_PASSWORD: "litlyx"
|
||||||
|
|
||||||
|
# Optional - Used for Lit, the AI analyst
|
||||||
# Optional - Used to use Lit, the AI analyst
|
|
||||||
|
|
||||||
# NUXT_AI_ORG: 'OPEN_AI_ORGANIZATION'
|
# NUXT_AI_ORG: 'OPEN_AI_ORGANIZATION'
|
||||||
# NUXT_AI_PROJECT: 'OPEN_AI_PROJECT'
|
# NUXT_AI_PROJECT: 'OPEN_AI_PROJECT'
|
||||||
@@ -80,7 +86,6 @@ services:
|
|||||||
|
|
||||||
NUXT_AUTH_JWT_SECRET: "litlyx_jwt_secret"
|
NUXT_AUTH_JWT_SECRET: "litlyx_jwt_secret"
|
||||||
|
|
||||||
|
|
||||||
# Optional - Used to register / login via google
|
# Optional - Used to register / login via google
|
||||||
|
|
||||||
# NUXT_GOOGLE_AUTH_CLIENT_ID: ""
|
# NUXT_GOOGLE_AUTH_CLIENT_ID: ""
|
||||||
@@ -101,7 +106,6 @@ services:
|
|||||||
# NUXT_STRIPE_SECRET_TEST: ""
|
# NUXT_STRIPE_SECRET_TEST: ""
|
||||||
# NUXT_STRIPE_WH_SECRET_TEST: ""
|
# NUXT_STRIPE_WH_SECRET_TEST: ""
|
||||||
|
|
||||||
|
|
||||||
# Optional - Stripe secret - Used to change plans of the projects
|
# Optional - Stripe secret - Used to change plans of the projects
|
||||||
|
|
||||||
# NUXT_STRIPE_SECRET: ""
|
# NUXT_STRIPE_SECRET: ""
|
||||||
|
|||||||
Reference in New Issue
Block a user