-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
56 lines (46 loc) · 1.37 KB
/
Copy pathserver.ts
File metadata and controls
56 lines (46 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import express from "express";
import path from "path";
import dns from "dns";
import { promisify } from "util";
import { validateEmailFull } from "./src/lib/validator";
const resolveMx = promisify(dns.resolveMx);
const app = express();
const PORT = 3000;
import batchHandler from './api/validate-batch';
export async function createServer() {
app.use(express.json());
// API Routes
app.get("/api/health", (req, res) => {
res.json({
status: "ok",
node: process.version,
env: process.env.NODE_ENV,
});
});
// Local Development Route - Mount the native Vercel handler in Express
app.post("/api/validate-batch", batchHandler);
// Vite middleware for development
if (process.env.NODE_ENV !== "production") {
const { createServer: createViteServer } = await import("vite");
const vite = await createViteServer({
server: { middlewareMode: true },
appType: "spa",
});
app.use(vite.middlewares);
} else {
const distPath = path.join(process.cwd(), 'dist');
app.use(express.static(distPath));
app.get('*', (req, res) => {
res.sendFile(path.join(distPath, 'index.html'));
});
}
return app;
}
if (process.env.NODE_ENV !== "test") {
createServer().then((app) => {
app.listen(PORT, "0.0.0.0", () => {
console.log(`Server running on http://localhost:${PORT}`);
});
});
}
export default app;