-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (27 loc) · 1.23 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Imports libraries used in the server file
const express = require('express');
const path = require('path');
// imports express library, and sets it working directory to the public folder and info collection from the post method
const app = express();
app.use(express.urlencoded({extended:true}));
app.use(express.static(__dirname + '/public'));
// Sets relative paths to retrieve certain files from the node_modules folder
app.use('/build/', express.static(path.join(__dirname, 'node_modules/three/build')));
app.use('/cannon/', express.static(path.join(__dirname, 'node_modules/cannon-es')));
app.use('/jsm/', express.static(path.join(__dirname, 'node_modules/three/examples/jsm')));
// sets working directory for view engine to views folder
app.set('view engine', 'ejs');
app.get('/', (req,res) => {
res.redirect('/home');
});
app.get('/home', (req,res) => {
res.render('index', {
title: 'Home'
});
});
// If user enters an unknown address, this function will activate
app.use((req,res) => {
res.status(404).render('404', {title: '404'});
});
// Runs server from port 3000 if in production environment
app.listen(3000, ()=> console.log('The server is running on port 3000'));