2023-04-22 13:23:29 -07:00
|
|
|
import express from "express";
|
|
|
|
|
import path from "path";
|
|
|
|
|
import pingRouter from "./routes/ping.js";
|
|
|
|
|
import indexRouter from "./routes/index.js";
|
|
|
|
|
import sassMiddleware from "node-sass-middleware";
|
|
|
|
|
import logger from "morgan";
|
|
|
|
|
import cookieParser from "cookie-parser";
|
|
|
|
|
import * as url from 'url';
|
2023-01-04 01:03:54 -08:00
|
|
|
|
2023-04-22 13:23:29 -07:00
|
|
|
const __filename = url.fileURLToPath(import.meta.url);
|
|
|
|
|
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
2023-01-04 01:03:54 -08:00
|
|
|
|
|
|
|
|
let app = express();
|
|
|
|
|
|
2023-04-22 13:23:29 -07:00
|
|
|
let port = process.env.PORT || '3003'
|
|
|
|
|
//let port = normalizePort(process.env.PORT || '3003');
|
|
|
|
|
app.set('port', port);
|
|
|
|
|
|
2023-01-04 01:03:54 -08:00
|
|
|
let log = false;
|
|
|
|
|
|
2023-04-22 13:23:29 -07:00
|
|
|
// if(process.env.PORT) port = process.env.PORT;
|
2023-01-04 01:03:54 -08:00
|
|
|
if(process.env.LOG) log = process.env.LOG;
|
|
|
|
|
|
|
|
|
|
console.log("Running on port: " + port);
|
|
|
|
|
|
|
|
|
|
if(log) app.use(logger('dev'));
|
|
|
|
|
app.use(express.json());
|
|
|
|
|
app.use(express.urlencoded({ extended: false }));
|
|
|
|
|
app.use(cookieParser());
|
|
|
|
|
app.use(sassMiddleware({
|
|
|
|
|
src: path.join(__dirname, 'public'),
|
|
|
|
|
dest: path.join(__dirname, 'public'),
|
|
|
|
|
indentedSyntax: true, // true = .sass and false = .scss
|
|
|
|
|
sourceMap: true
|
|
|
|
|
}));
|
|
|
|
|
//app.use(express.static(path.join(__dirname, 'public')));
|
|
|
|
|
|
|
|
|
|
app.use('/', indexRouter);
|
|
|
|
|
app.use('/ping', pingRouter);
|
|
|
|
|
|
|
|
|
|
app.listen(port);
|
|
|
|
|
|
2023-04-22 13:23:29 -07:00
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * Module dependencies.
|
|
|
|
|
// */
|
|
|
|
|
//
|
|
|
|
|
// // let app = require('../app');
|
|
|
|
|
// let debug = require('debug')('avusddatacollection:server');
|
|
|
|
|
// let http = require('http');
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * Create HTTP server.
|
|
|
|
|
// */
|
|
|
|
|
//
|
|
|
|
|
// let server = http.createServer(app);
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * Listen on provided port, on all network interfaces.
|
|
|
|
|
// */
|
|
|
|
|
//
|
|
|
|
|
// server.listen(port);
|
|
|
|
|
// server.on('error', onError);
|
|
|
|
|
// server.on('listening', onListening);
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * Normalize a port into a number, string, or false.
|
|
|
|
|
// */
|
|
|
|
|
//
|
|
|
|
|
// function normalizePort(val) {
|
|
|
|
|
// let port = parseInt(val, 10);
|
|
|
|
|
//
|
|
|
|
|
// if (isNaN(port)) {
|
|
|
|
|
// // named pipe
|
|
|
|
|
// return val;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (port >= 0) {
|
|
|
|
|
// // port number
|
|
|
|
|
// return port;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * Event listener for HTTP server "error" event.
|
|
|
|
|
// */
|
|
|
|
|
//
|
|
|
|
|
// function onError(error) {
|
|
|
|
|
// if (error.syscall !== 'listen') {
|
|
|
|
|
// throw error;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// let bind = typeof port === 'string'
|
|
|
|
|
// ? 'Pipe ' + port
|
|
|
|
|
// : 'Port ' + port;
|
|
|
|
|
//
|
|
|
|
|
// // handle specific listen errors with friendly messages
|
|
|
|
|
// switch (error.code) {
|
|
|
|
|
// case 'EACCES':
|
|
|
|
|
// console.error(bind + ' requires elevated privileges');
|
|
|
|
|
// process.exit(1);
|
|
|
|
|
// break;
|
|
|
|
|
// case 'EADDRINUSE':
|
|
|
|
|
// console.error(bind + ' is already in use');
|
|
|
|
|
// process.exit(1);
|
|
|
|
|
// break;
|
|
|
|
|
// default:
|
|
|
|
|
// throw error;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * Event listener for HTTP server "listening" event.
|
|
|
|
|
// */
|
|
|
|
|
//
|
|
|
|
|
// function onListening() {
|
|
|
|
|
// let addr = server.address();
|
|
|
|
|
// let bind = typeof addr === 'string'
|
|
|
|
|
// ? 'pipe ' + addr
|
|
|
|
|
// : 'port ' + addr.port;
|
|
|
|
|
// debug('Listening on ' + bind);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
//module.exports = app;
|
|
|
|
|
export default app
|