HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: /var/www/api.javaapp.co.uk/server.js
import express, { json, Router, urlencoded } from "express";

const app = express();
import morgan from "morgan";
import http from "http";
import https from "https";
import fs from "fs";
import { config } from "./src/config/config.js";
import { router } from "./src/routers/index.router.js";
import sequelize from "./src/config/database.config.js";
import * as indexRouter from "./src/models/index.model.js";
import fileUpload from "express-fileupload";
import schedule from "./src/helper/schedule.js";

app.use(json());

app.use(fileUpload());

app.use(morgan("dev"))

app.use(router);

// manage 404 error
app.use((req, res, next) => {
  res.status(404).json({
    status: 404,
    message: 'Ohh you are lost, read the API documentation to find your way back home :)'
  })
})

/**
 * Create HTTP server.
 */
var mode = process.env.HTTPS_MODE || 'HTTPS';

if (mode == "HTTPS") {
  var options = {
    key: fs.readFileSync(process.env.SSL_PRIVATE_KEY_FILE,'utf8'), 
    cert: fs.readFileSync(process.env.SSL_FULL_CHAIN_FILE,'utf8')
  };
  var server = https.createServer(options, app);
} else {
  var server = http.createServer(app);
}

const PORT = config.port;
server.listen(PORT, '0.0.0.0',() => {
  console.log("listening on port ", PORT);
});