Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
Latest commit
57 lines (45 loc) · 1.67 KB
/
Copy pathindex.js
File metadata and controls
57 lines (45 loc) · 1.67 KB
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
constexpress=require('express');
constpath=require('path');
constaxios=require('axios');
constapp=express();
// Use port 0 to let the OS assign an available port
constPORT=0;
// Set EJS as the template engine
app.set('view engine','ejs');
// Set the 'views' directory for any views being rendered
app.set('views',path.join(__dirname,'views'));
// Serve static files from the 'public' directory
app.use(express.static(path.join(__dirname,'public')));
// Function to get the latest release file URLs
asyncfunctiongetLatestFileUrls(){
constrepo='ScriptBlocks/ScriptBlocks';
constfilenames=['scriptblocks.exe','scriptblocks.dmg','scriptblocks.tar.gz'];
constapiUrl=`https://api.github.com/repos/${repo}/releases/latest`;
try{
constresponse=awaitaxios.get(apiUrl);
constassets=response.data.assets;
constfileUrls={};
filenames.forEach(filename=>{
constfile=assets.find(asset=>asset.name===filename);
fileUrls[filename]=file ? file.browser_download_url : null;
});
returnfileUrls;
}catch(error){
console.error('Error fetching the latest release data:',error);
return{};
}
}
// Define routes
app.get('/',async(req,res)=>{
constfileUrls=awaitgetLatestFileUrls();
res.render('index',{title: 'Home', fileUrls });
});
app.get('/store',async(req,res)=>{
res.render('store',{title: 'Store'});
});
// Start the server
constserver=app.listen(PORT,()=>{
// Retrieve the dynamically assigned port
constport=server.address().port;
console.log(`Server is running on http://localhost:${port}`);
});