app.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const express = require('express');
  2. const bodyParser = require('body-parser');
  3. const routes = require('./routes/route');
  4. const https=require("https");
  5. //const routes = require('../DVR-BACKEND/routes/route');
  6. const fs = require('fs');
  7. const app = express();
  8. const cors= require('cors');
  9. const port = process.env.PORT || 9000;
  10. app.use(bodyParser.urlencoded({ extended: false }));
  11. app.use(express.json());
  12. app.use(express.urlencoded({
  13. extended: true
  14. }));
  15. // const options = {
  16. // key: fs.readFileSync('./certificate/private.key'),
  17. // cert: fs.readFileSync('./certificate/certificate.crt')
  18. // };
  19. app.use(cors())
  20. app.use('/', routes);
  21. app.all('/*', function (req, res, next) {
  22. res.header("Access-Control-Allow-Origin", "*");
  23. res.header("Access-Control-Allow-Methods", "*");
  24. res.header("Access-Control-Allow-Headers", "*");
  25. next();
  26. });
  27. // https.createServer(options, app).listen(port, () => {
  28. // console.log(` listening port at https://localhost:${port}`)
  29. // });
  30. app.listen(port,()=>{
  31. console.log("listening port at http://localhost:9000");
  32. })