Skip to content

Commit

Permalink
chore: initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
birme committed Nov 4, 2024
1 parent 97a1d12 commit 1813b0b
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.next/
out/
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
9 changes: 9 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import('next').NextConfig} */
module.exports = {
output: 'export',
trailingSlash: true,
poweredByHeader: false,
experimental: {
instrumentationHook: true
}
};
25 changes: 20 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
"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",
"lint": "eslint .",
"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": {
Expand All @@ -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",
Expand All @@ -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"
}
}
8 changes: 8 additions & 0 deletions postcss.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: {
tailwindcss: {}
}
};

export default config;
9 changes: 7 additions & 2 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!'
Expand Down Expand Up @@ -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;
}
19 changes: 19 additions & 0 deletions src/api_service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export interface ApiServiceOptions {
openAiApiKey: string;
}

const apiService: FastifyPluginCallback<ApiServiceOptions> = (
fastify,
opts,
next
) => {
fastify.setErrorHandler((error, request, reply) => {
reply.code(500).send({ reason: error.message });
});

// Insert routes here

next();
};

export default apiService;
9 changes: 8 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
15 changes: 15 additions & 0 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -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;
18 changes: 16 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}

0 comments on commit 1813b0b

Please sign in to comment.