format codebase with prettier
This commit is contained in:
@@ -1,28 +1,35 @@
|
||||
import express from 'express';
|
||||
import mongoose from 'mongoose';
|
||||
import 'dotenv/config'
|
||||
import express from "express";
|
||||
import mongoose from "mongoose";
|
||||
import "dotenv/config";
|
||||
|
||||
import { createRoutes } from './routes';
|
||||
import { AuthController, ChatController, EventController } from './controllers';
|
||||
import { AuthService, ChatService, EventService } from './services';
|
||||
import { MongoUserRepository, MongoEventRepository, MongoChatRepository } from './repositories';
|
||||
import { ClaudeAdapter } from './ai';
|
||||
import { createRoutes } from "./routes";
|
||||
import { AuthController, ChatController, EventController } from "./controllers";
|
||||
import { AuthService, ChatService, EventService } from "./services";
|
||||
import {
|
||||
MongoUserRepository,
|
||||
MongoEventRepository,
|
||||
MongoChatRepository,
|
||||
} from "./repositories";
|
||||
import { ClaudeAdapter } from "./ai";
|
||||
|
||||
const app = express();
|
||||
const port = process.env.PORT || 3000;
|
||||
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/caldav';
|
||||
const mongoUri = process.env.MONGODB_URI || "mongodb://localhost:27017/caldav";
|
||||
|
||||
// Middleware
|
||||
app.use(express.json());
|
||||
|
||||
// CORS - only needed for web browser development
|
||||
// Native mobile apps don't send Origin headers and aren't affected by CORS
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
app.use((req, res, next) => {
|
||||
res.header('Access-Control-Allow-Origin', '*');
|
||||
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
||||
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
||||
if (req.method === 'OPTIONS') {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
res.header(
|
||||
"Access-Control-Allow-Methods",
|
||||
"GET, POST, PUT, DELETE, OPTIONS",
|
||||
);
|
||||
res.header("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
||||
if (req.method === "OPTIONS") {
|
||||
res.sendStatus(200);
|
||||
return;
|
||||
}
|
||||
@@ -49,34 +56,37 @@ const chatController = new ChatController(chatService);
|
||||
const eventController = new EventController(eventService);
|
||||
|
||||
// Setup routes
|
||||
app.use('/api', createRoutes({
|
||||
authController,
|
||||
chatController,
|
||||
eventController,
|
||||
}));
|
||||
app.use(
|
||||
"/api",
|
||||
createRoutes({
|
||||
authController,
|
||||
chatController,
|
||||
eventController,
|
||||
}),
|
||||
);
|
||||
|
||||
// Health check
|
||||
app.get('/health', (_, res) => {
|
||||
res.json({ status: 'ok' });
|
||||
app.get("/health", (_, res) => {
|
||||
res.json({ status: "ok" });
|
||||
});
|
||||
|
||||
// AI Test endpoint (for development only)
|
||||
app.post('/api/ai/test', async (req, res) => {
|
||||
app.post("/api/ai/test", async (req, res) => {
|
||||
try {
|
||||
const { message } = req.body;
|
||||
if (!message) {
|
||||
res.status(400).json({ error: 'message is required' });
|
||||
res.status(400).json({ error: "message is required" });
|
||||
return;
|
||||
}
|
||||
const result = await aiProvider.processMessage(message, {
|
||||
userId: 'test-user',
|
||||
userId: "test-user",
|
||||
conversationHistory: [],
|
||||
existingEvents: [],
|
||||
currentDate: new Date(),
|
||||
});
|
||||
res.json(result);
|
||||
} catch (error) {
|
||||
console.error('AI test error:', error);
|
||||
console.error("AI test error:", error);
|
||||
res.status(500).json({ error: String(error) });
|
||||
}
|
||||
});
|
||||
@@ -85,13 +95,13 @@ app.post('/api/ai/test', async (req, res) => {
|
||||
async function start() {
|
||||
try {
|
||||
await mongoose.connect(mongoUri);
|
||||
console.log('Connected to MongoDB');
|
||||
console.log("Connected to MongoDB");
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Server running on port ${port}`);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Failed to start server:', error);
|
||||
console.error("Failed to start server:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user