Merge branch 'main' into feat-endpoint-style-structure

This commit is contained in:
Daniel Avila 2023-04-01 19:41:36 -04:00
commit 8fa20d9356
18 changed files with 2281 additions and 24 deletions

View file

@ -23,7 +23,7 @@ const projectPath = path.join(__dirname, '..', '..', 'client');
app.use(errorController); app.use(errorController);
app.use(cors()); app.use(cors());
app.use(express.json()); app.use(express.json());
app.use(express.static(path.join(projectPath, 'public'))); app.use(express.static(path.join(projectPath, 'dist')));
app.set('trust proxy', 1); // trust first proxy app.set('trust proxy', 1); // trust first proxy
app.use( app.use(
session({ session({
@ -73,7 +73,7 @@ const projectPath = path.join(__dirname, '..', '..', 'client');
}); });
app.get('/*', routes.authenticatedOrRedirect, function (req, res) { app.get('/*', routes.authenticatedOrRedirect, function (req, res) {
res.sendFile(path.join(projectPath, 'public', 'index.html')); res.sendFile(path.join(projectPath, 'dist', 'index.html'));
}); });
app.listen(port, host, () => { app.listen(port, host, () => {

View file

@ -26,15 +26,16 @@
/> />
<script <script
defer defer
src="/main.js" type="module"
src="/src/main.jsx"
></script> ></script>
</head> </head>
<body> <body>
<div id="root"></div> <div id="root"></div>
<script <script
type="text/javascript" type="module"
src="/main.js" src="/src/main.jsx"
></script> ></script>
</body> </body>
</html> </html>

View file

@ -2,9 +2,11 @@
"name": "chatgpt-clone", "name": "chatgpt-clone",
"version": "0.2.0", "version": "0.2.0",
"description": "", "description": "",
"main": "index.js", "type": "module",
"scripts": { "scripts": {
"build": "webpack", "build": "vite build",
"dev": "vite",
"preview-prod": "vite preview",
"build-dev": "Webpack . --watch" "build-dev": "Webpack . --watch"
}, },
"repository": { "repository": {

View file

@ -0,0 +1,8 @@
module.exports = {
plugins: [
require("postcss-import"),
require("postcss-preset-env"),
require("tailwindcss"),
require("autoprefixer"),
]
};

View file

@ -1,2 +0,0 @@
const tailwindcss = require('tailwindcss');
module.exports = { plugins: ['postcss-preset-env', tailwindcss] };

View file

@ -16,11 +16,12 @@ export default function Conversation({ conversation, retainView }) {
const { switchToConversation } = store.useConversation(); const { switchToConversation } = store.useConversation();
const [renaming, setRenaming] = useState(false); const [renaming, setRenaming] = useState(false);
const [titleInput, setTitleInput] = useState(title);
const inputRef = useRef(null); const inputRef = useRef(null);
const { conversationId, title } = conversation; const { conversationId, title } = conversation;
const [titleInput, setTitleInput] = useState(title);
const rename = manualSWR(`/api/convos/update`, 'post'); const rename = manualSWR(`/api/convos/update`, 'post');
const clickHandler = async () => { const clickHandler = async () => {

View file

@ -1,6 +1,6 @@
import { useEffect } from 'react'; import { useEffect } from 'react';
import { useRecoilValue, useResetRecoilState, useSetRecoilState } from 'recoil'; import { useRecoilValue, useResetRecoilState, useSetRecoilState } from 'recoil';
import { SSE } from '~/utils/sse'; import { SSE } from '~/utils/sse.mjs';
import createPayload from '~/utils/createPayload'; import createPayload from '~/utils/createPayload';
import store from '~/store'; import store from '~/store';

View file

@ -6,7 +6,7 @@ import remarkMath from 'remark-math';
import remarkGfm from 'remark-gfm'; import remarkGfm from 'remark-gfm';
import rehypeRaw from 'rehype-raw' import rehypeRaw from 'rehype-raw'
import CodeBlock from './CodeBlock'; import CodeBlock from './CodeBlock';
import { langSubset } from '~/utils/languages'; import { langSubset } from '~/utils/languages.mjs';
const Content = React.memo(({ content }) => { const Content = React.memo(({ content }) => {
let rehypePlugins = [ let rehypePlugins = [

View file

@ -42,5 +42,5 @@ export const ThemeProvider = ({ initialTheme, children }) => {
rawSetTheme(theme); rawSetTheme(theme);
}, [theme]); }, [theme]);
return <ThemeContext.Provider value={{ theme, setTheme }}>{children}</ThemeContext.Provider>; return <ThemeContext.Provider value={{ theme, setTheme }}>{children}</ThemeContext.Provider>
}; };

View file

@ -4,10 +4,10 @@ import { createRoot } from 'react-dom/client';
// import { store } from './src/store'; // import { store } from './src/store';
import { RecoilRoot } from 'recoil'; import { RecoilRoot } from 'recoil';
import { ThemeProvider } from './src/hooks/ThemeContext'; import { ThemeProvider } from './hooks/ThemeContext';
import App from './src/App'; import App from './App';
import './src/style.css'; import './style.css';
import './src/mobile.css'; import './mobile.css';
const container = document.getElementById('root'); const container = document.getElementById('root');
const root = createRoot(container); const root = createRoot(container);

View file

@ -353,4 +353,4 @@ const langSubset = [
'yaml', 'yaml',
]; ];
module.exports = { languages, langSubset }; export { languages, langSubset };

View file

@ -211,8 +211,9 @@ var SSE = function (url, options) {
}; };
}; };
export { SSE };
// Export our SSE module for npm.js // Export our SSE module for npm.js
if (typeof exports !== 'undefined') { // if (typeof exports !== 'undefined') {
// exports.SSE = SSE; // // exports.SSE = SSE;
module.exports = { SSE }; // module.exports = { SSE };
} // }

View file

@ -1,9 +1,31 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": [
"DOM",
"DOM.Iterable",
"ESNext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": false,
"module": "ESNext",
"moduleResolution": "nodenext",
"resolveJsonModule": true,
"isolatedModules": true,
"noImplicitAny": false,
"noEmit": false,
"jsx": "react-jsx",
"baseUrl": ".", "baseUrl": ".",
"jsx": "react",
"paths": { "paths": {
"~/*": ["./src/*"] "~/*": ["./src/*"]
} }
} },
"include": [
"src"
],
} }

29
client/vite.config.ts Normal file
View file

@ -0,0 +1,29 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import path from 'path';
// https://vitejs.dev/config/
export default defineConfig({
server: {
host: "localhost",
port: 3090,
strictPort: false,
proxy: {
"/api": {
target: "http://localhost:3080",
changeOrigin: true,
}
}
},
plugins: [react()],
publicDir: "./public",
build: {
sourcemap: true,
outDir: "./dist",
},
resolve: {
alias: {
"~": path.join(__dirname, "src/"),
},
},
});

2188
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

7
package.json Normal file
View file

@ -0,0 +1,7 @@
{
"devDependencies": {
"@vitejs/plugin-react": "^3.1.0",
"vite": "^4.2.1",
"vite-plugin-html": "^3.2.0"
}
}