77 lines
2.2 KiB
JavaScript
77 lines
2.2 KiB
JavaScript
require('dotenv').config();
|
|
|
|
const express = require('express');
|
|
const basicAuth = require('express-basic-auth');
|
|
const helmet = require('helmet');
|
|
const cors = require('cors');
|
|
|
|
const path = require('path');
|
|
const http = require('http');
|
|
const favicon = require('serve-favicon');
|
|
const logger = require('morgan');
|
|
const cookieParser = require('cookie-parser');
|
|
const bodyParser = require('body-parser');
|
|
const routes = require('./routes/index');
|
|
const users = require('./routes/users');
|
|
const timeroute = require('./server/routes/time');
|
|
const btcroute = require('./server/routes/btc');
|
|
const temproute = require('./server/routes/temp');
|
|
const weightroute = require('./routes/weight');
|
|
const weatherRoute = require('./server/routes/weather');
|
|
const geocodeRoute = require('./server/routes/geocode');
|
|
|
|
const app = express();
|
|
GLOBAL.lastcheck = { 'btc': 0, 'fx': 0 };
|
|
|
|
app.set('port', process.env.PORT || 8030);
|
|
app.set('views', path.join(__dirname, 'views'));
|
|
app.set('view engine', 'ejs');
|
|
app.use(logger('dev'));
|
|
|
|
app.use(cors());
|
|
|
|
/*app.use(basicAuth({
|
|
'users': {
|
|
'testmvc': '9E#!7!Nu5kd$FnCBQj_=Bh6WgGPqG@g-ETK%y3Ht+87rRT!Vvp=DH=6&w7mJ*36!',
|
|
'jubilee' : '_TX2LD6n8csqE=TcPNR#h&4b%Mh_YdDNbe@vwAwhY^7=?AAL@U^SF2rwHxRQt4#M',
|
|
'simpleweather' : 'stq^J4rZ%c=F+2ym^GRxB*^+5?XC!#Xjv6n6?Sb9kP4y@26puAt@*n8zvSqG$#dW',
|
|
'weatherapp' : '!t@M6f+Wz#-3BpWVC5GLMrb7DrdhenXCxKDkL%g2!CPsRx4#&GFz$BUPvgPn?Z=A'
|
|
}
|
|
}));*/
|
|
|
|
app.use(helmet());
|
|
|
|
app.use(bodyParser.json());
|
|
app.use(bodyParser.urlencoded({ 'extended': true }));
|
|
app.use(cookieParser());
|
|
app.use(express.static(path.join(__dirname, 'public')));
|
|
|
|
app.use('/', routes);
|
|
// app.use('/users', users);
|
|
|
|
app.use('/time', timeroute);
|
|
app.use('/btc', btcroute);
|
|
app.use('/temp', temproute);
|
|
app.use('/weight', weightroute);
|
|
app.use('/weather', weatherRoute);
|
|
app.use('/geocode', geocodeRoute);
|
|
|
|
// Handle 404
|
|
app.use((req, res) => {
|
|
res.status(404).send('404: Page not Found');
|
|
});
|
|
|
|
// Handle 500
|
|
app.use((error, req, res, next) => {
|
|
console.log(error);
|
|
res.status(500).send('500: Internal Server Error');
|
|
});
|
|
|
|
/**
|
|
* create the server
|
|
*/
|
|
|
|
app.listen(app.get('port'), function() {
|
|
console.log(`APIServer listening on ${ app.get('port')}`);
|
|
});
|