MangoShelf/Components/webserver.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-09-16 21:57:13 +02:00
// Import things
const express = require('express');
const app = express();
const server = require('http').createServer(app);
const port = process.env.PORT || 3430;
2022-09-19 23:55:23 +02:00
const test = require('../testdatabase.json');
var site;
// TODO: Add stuff for MySQL
2022-09-16 21:57:13 +02:00
// Set the templates folder for the thingy
app.set('views', __dirname + '/../Templates');
app.set('view engine', 'ejs');
// Makes it so that the Public folder mounts under /
app.use(express.static(__dirname + '/../Public'));
// Main page
app.get('/', function(req, res){
2022-09-19 23:55:23 +02:00
console.log('🌐 Client requested ' + req.url);
res.render('index', { test, site: 1 });
console.log('✅ Client recieved ' + req.url);
// console.log(test.cars.Nissan[1].model)
});
app.get('/inventory', function(req, res){
console.log('🌐 Client requested ' + req.url);
res.render('index', { test, site: 2 });
console.log('✅ Client recieved ' + req.url);
// console.log(test.cars.Nissan[1].model)
2022-09-16 21:57:13 +02:00
});
// Simple way to expose a function
exports = module.exports = rws;
// rws = RunWebServer
function rws() {
server.listen(port, () => {
console.log('✅ Webserver is running ( %d )', port);
});
};