-
Notifications
You must be signed in to change notification settings - Fork 23
/
server.js
90 lines (75 loc) · 2.69 KB
/
server.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const Vimeo = require('vimeo').Vimeo;
const express = require('express');
const hostValidation = require('host-validation')
const ejs = require('ejs');
const app = express();
// Render engine for the express server
app.use(express.static('dist'));
app.use(express.static('ext'));
app.use(express.static('assets'));
app.engine('.html', ejs.__express);
app.set('view-engine', 'html');
app.set('views', __dirname + '/examples');
// CORS headers
app.use(function(req, res, next) {
console.log(`[Server] A ${req.method} request was made to ${req.url}`);
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
});
/*
* Vimeo token for local development is saved in a .env file
* For deployment make sure to store it in an enviorment
* variable called VIMEO_TOKEN=4trwegfudsbg4783724343
*/
if (process.env.NODE_ENV !== 'production') {
require('dotenv').load();
if (process.env.VIMEO_TOKEN) {
console.log('[Server] Enviorment variables loaded from .env 💪🏻');
} else {
console.log('[Server] Could not find a VIMEO_TOKEN. Make sure you have a .env file or enviorment variable with the token');
}
}
app.use(hostValidation({ hosts: [`127.0.0.1:${process.env.PORT}`,
`192.168.1.99:${process.env.PORT}`,
`localhost:${process.env.PORT}`,
/.*\.glitch\.com$/,
/.*\.glitch\.me$/,
`${process.env.DOMAIN}:${process.env.PORT}`] }))
app.get('/', (request, response) => {
response.render('basic.html');
});
app.get('/basic', (request, response) => {
response.render('basic.html');
});
app.get('/shapes', (request, response) => {
response.render('shapes.html');
});
app.get('/webvr-stereo', (request, response) => {
response.render('webvr-stereo.html');
});
app.get('/playback', (request, response) => {
response.render('playback.html');
});
// The route for getting videos from the vimeo API
app.get('/vimeo/api', (request, response) => {
let api = new Vimeo(null, null, process.env.VIMEO_TOKEN);
api.request({
method: 'GET',
path: request.query.path,
headers: { Accept: 'application/vnd.vimeo.*+json;version=3.4' },
},
function(error, body, status_code, headers) {
if (error) {
response.status(500).send(error);
console.log('[Server] ' + error);
} else {
// Pass through the whole JSON response
response.status(200).send(body);
}
}
);
});
const listener = app.listen(process.env.PORT, () => {
console.log(`[Server] Running on port: ${listener.address().port} 🚢`);
});