-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
57 lines (50 loc) · 1.7 KB
/
Copy pathindex.js
File metadata and controls
57 lines (50 loc) · 1.7 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
57
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const cors = require("cors");
const path = require('path');
require("dotenv").config({ path: `.env.local` });
async function initApp() {
// await db.initMySQL();
await initExpress();
await initRoutes();
await launchServer();
}
async function initExpress() {
app.set("views", path.join(__dirname, "views"));
app.set("view cache", false);
app.use(bodyParser.urlencoded({ limit: "10mb", extended: true }));
app.use(bodyParser.json({ limit: "10mb" }));
// Set up a whitelist and check against it:
// let whitelist = [
// "http://localhost:5173",
// "http://localhost:5173/cani/1.jpg",
// "*",
// ]; // Replace with your client's origin(s)
// let corsOptions = {
// origin: "http://localhost:5173", // This will allow access from all origins
// methods: "GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS", // Allowed HTTP methods
// preflightContinue: true,
// allowTainte: false,
// optionsSuccessStatus: 204,
// // AccessControlAllowOrigin: "*",
// };
// Serve static files from public
app.use(express.static(path.join(__dirname, 'public')));
// Serve Bootstrap from node_modules
app.use('/bootstrap', express.static(path.join(__dirname, 'node_modules/bootstrap/dist')));
app.use(cors());
app.use(express.static("assets"));
}
async function initRoutes() {
const websiteRoutes = require("./routes/Website.routes");
app.use("/", websiteRoutes);
// const officeRoutes = require("./routes/Office.routes");
// app.use("/office", officeRoutes);
}
async function launchServer() {
app.listen(8000, async function () {
console.log("listening on port 8000");
});
}
initApp();