-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
44 lines (36 loc) · 1.19 KB
/
app.js
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
// app.js
const express = require("express");
const bodyParser = require("body-parser");
const database = require("./database");
const app = express();
const mysql = require("mysql");
const port = 8080;
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "http://localhost:3000");
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
next();
});
app.use(bodyParser.json());
const pool = mysql.createPool({
connectionLimit: 10,
host: "localhost",
user: "root",
password: "admin1234",
database: "barcode_scanner",
});
// Create the tables before starting the server
database.createTables(pool);
const authRoutes = require("./routes/auth")(pool);
const recordsRoutes = require("./routes/records")(pool);
const barcodeRoutes = require("./routes/barcode")(pool);
const warehouseRoutes = require("./routes/warehouse")(pool);
// Use the route handlers
app.use(authRoutes);
app.use(recordsRoutes);
app.use(barcodeRoutes);
app.use(warehouseRoutes);
// Rest of your API routes and logic...
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});