added backend implementation
This commit is contained in:
54
backend/index.js
Normal file
54
backend/index.js
Normal file
@ -0,0 +1,54 @@
|
||||
import serversideConfig from '../serversideConfig.js';
|
||||
|
||||
//import express
|
||||
import express from "express";
|
||||
|
||||
//import cors
|
||||
import cors from "cors";
|
||||
|
||||
//import https
|
||||
import https from "https";
|
||||
|
||||
//import fs
|
||||
import fs from "fs";
|
||||
|
||||
//import routes
|
||||
import Router from "./routes/routes.js";
|
||||
|
||||
//init express
|
||||
const app = express();
|
||||
|
||||
//setup cors
|
||||
const corsOptions = {
|
||||
origin: 'https://localhost:4173',
|
||||
headers: 'authorization, content-type',
|
||||
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
|
||||
credentials: true,
|
||||
optionsSuccessStatus: 204,
|
||||
};
|
||||
|
||||
//use cors
|
||||
app.use(cors(corsOptions));
|
||||
|
||||
//use express json
|
||||
app.use(express.json());
|
||||
|
||||
//use router
|
||||
app.use(Router);
|
||||
|
||||
//setup https
|
||||
var privateKey = fs.readFileSync('../certs/localhost.key');
|
||||
var certificate = fs.readFileSync('../certs/localhost.crt');
|
||||
|
||||
var server = https.createServer({
|
||||
key: privateKey,
|
||||
cert: certificate
|
||||
}, app);
|
||||
|
||||
// const PORT = process.env.PORT || 5172;
|
||||
const PORT = process.env.PORT || config.port;
|
||||
|
||||
//PORT
|
||||
server.listen(PORT, () => {
|
||||
console.log(`Server running successfully (port ${PORT})`);
|
||||
});
|
||||
Reference in New Issue
Block a user