From 1813b0b55a1a0cea23815bd9caa18bd810c154a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Birm=C3=A9?= Date: Mon, 4 Nov 2024 14:13:26 +0100 Subject: [PATCH] chore: initial setup --- .prettierignore | 2 ++ Dockerfile | 6 ++++-- next.config.js | 9 +++++++++ package.json | 25 ++++++++++++++++++++----- postcss.config.mjs | 8 ++++++++ src/api.ts | 9 +++++++-- src/api_service.ts | 19 +++++++++++++++++++ src/server.ts | 9 ++++++++- tailwind.config.ts | 15 +++++++++++++++ tsconfig.json | 18 ++++++++++++++++-- 10 files changed, 108 insertions(+), 12 deletions(-) create mode 100644 .prettierignore create mode 100644 next.config.js create mode 100644 postcss.config.mjs create mode 100644 src/api_service.ts create mode 100644 tailwind.config.ts diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..4c46336 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +.next/ +out/ diff --git a/Dockerfile b/Dockerfile index 68cc37b..2cee26f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,9 +7,11 @@ RUN mkdir /app RUN chown node:node /app USER node WORKDIR /app -COPY --chown=node:node ["package.json", "package-lock.json*", "tsconfig*.json", "./"] -COPY --chown=node:node ["src", "./src"] +#COPY --chown=node:node ["package.json", "package-lock.json*", "tsconfig*.json", "./"] +#COPY --chown=node:node ["src", "./src"] +COPY --chown=node:node . . # Delete prepare script to avoid errors from husky RUN npm pkg delete scripts.prepare \ && npm ci --omit=dev +RUN npm run build:app CMD [ "npm", "run", "start" ] diff --git a/next.config.js b/next.config.js new file mode 100644 index 0000000..6ca2bec --- /dev/null +++ b/next.config.js @@ -0,0 +1,9 @@ +/** @type {import('next').NextConfig} */ +module.exports = { + output: 'export', + trailingSlash: true, + poweredByHeader: false, + experimental: { + instrumentationHook: true + } +}; diff --git a/package.json b/package.json index f00d9fc..13d61c0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "@eyevinn/typescript-nodejs", + "name": "AI Agent", "version": "1.0.0", - "description": "The default typescript-nodejs template for eyevinn projects", + "description": "White-label AI chat service ready to be embedded on your site", "scripts": { "test": "jest", "prepare": "husky install", @@ -9,7 +9,10 @@ "pretty": "prettier --check --ignore-unknown .", "typecheck": "tsc --noEmit -p tsconfig.json", "dev": "nodemon", - "start": "ts-node -T src/server.ts" + "dev:app": "NODE_OPTIONS='--inspect' NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1 next dev", + "build:app": "next build", + "start": "ts-node -T src/server.ts", + "postversion": "git push && git push --tags" }, "license": "MIT", "engines": { @@ -23,7 +26,15 @@ "@sinclair/typebox": "^0.29.0", "fastify": "4.23.2", "nodemon": "^2.0.20", - "ts-node": "^10.9.1" + "ts-node": "^10.9.1", + "@fastify/static": "^7.0.4", + "@next/third-parties": "^14.2.13", + "@nextui-org/react": "^2.4.6", + "@tabler/icons-react": "^3.19.0", + "next": "^14.2.15", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "tailwind-merge": "^2.5.4" }, "devDependencies": { "@commitlint/cli": "^17.4.2", @@ -39,6 +50,10 @@ "jest": "^29.5.0", "prettier": "^2.8.4", "ts-jest": "^29.0.5", - "typescript": "^4.9.5" + "typescript": "^4.9.5", + "@types/react": "^18.2.37", + "@types/react-dom": "^18.2.15", + "postcss": "^8", + "tailwindcss": "^3.4.1" } } diff --git a/postcss.config.mjs b/postcss.config.mjs new file mode 100644 index 0000000..df76ed2 --- /dev/null +++ b/postcss.config.mjs @@ -0,0 +1,8 @@ +/** @type {import('postcss-load-config').Config} */ +const config = { + plugins: { + tailwindcss: {} + } +}; + +export default config; diff --git a/src/api.ts b/src/api.ts index 9f5e143..af60649 100644 --- a/src/api.ts +++ b/src/api.ts @@ -5,6 +5,7 @@ import swaggerUI from '@fastify/swagger-ui'; import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox'; import { Static, Type } from '@sinclair/typebox'; import { FastifyPluginCallback } from 'fastify'; +import apiService from './api_service'; const HelloWorld = Type.String({ description: 'The magical words!' @@ -55,11 +56,15 @@ export default (opts: ApiOptions) => { } }); api.register(swaggerUI, { - routePrefix: '/docs' + routePrefix: '/api/docs' }); - api.register(healthcheck, { title: opts.title }); + api.register(healthcheck, { prefix: '/api', title: opts.title }); // register other API routes here + api.register(apiService, { + prefix: '/api/v1' + }); + return api; } diff --git a/src/api_service.ts b/src/api_service.ts new file mode 100644 index 0000000..b3b06fd --- /dev/null +++ b/src/api_service.ts @@ -0,0 +1,19 @@ +export interface ApiServiceOptions { + openAiApiKey: string; +} + +const apiService: FastifyPluginCallback = ( + fastify, + opts, + next +) => { + fastify.setErrorHandler((error, request, reply) => { + reply.code(500).send({ reason: error.message }); + }); + + // Insert routes here + + next(); +}; + +export default apiService; diff --git a/src/server.ts b/src/server.ts index bf9a471..aa9b178 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,6 +1,13 @@ +import fastifyStatic from '@fastify/static'; +import path from 'path'; import api from './api'; -const server = api({ title: '@eyevinn/typescript-nodejs' }); +const server = api({ title: 'White Label AI chat service' }); + +server.register(fastifyStatic, { + root: path.join(__dirname, '../out'), + prefix: '/' +}); const PORT = process.env.PORT ? Number(process.env.PORT) : 8000; diff --git a/tailwind.config.ts b/tailwind.config.ts new file mode 100644 index 0000000..86bcddc --- /dev/null +++ b/tailwind.config.ts @@ -0,0 +1,15 @@ +import { nextui } from '@nextui-org/react'; +import type { Config } from 'tailwindcss'; + +const config: Config = { + content: ['./node_modules/@nextui-org/theme/dist/**/*.{js,ts,jsx,tsx}'], + theme: { + extend: { + almostBlack: '#171717', + almostWhite: '#ededed' + } + }, + darkMode: 'class', + plugins: [nextui()] +}; +export default config; diff --git a/tsconfig.json b/tsconfig.json index 4726840..021d377 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,6 +12,20 @@ /* Modules */ "module": "commonjs" /* Specify what module code is generated. */, "resolveJsonModule": true /* Enable importing .json files. */, - "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */ - } + "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */, + "jsx": "preserve", + "plugins": [ + { + "name": "next" + } + ], + "paths": { + "@/*": ["./src/*"] + }, + "noEmit": true, + "incremental": true, + "isolatedModules": true + }, + "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], + "exclude": ["node_modules"] }