-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
323 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "simple-web-nodejs", | ||
"version": "1.0.0", | ||
"description": "A simple web server with [nodejs](https://nodejs.org/).", | ||
"private": true, | ||
"main": "server.js", | ||
"dependencies": {}, | ||
"devDependencies": {}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"start": "node server.js" | ||
}, | ||
"author": "Jiab77 <[email protected]>", | ||
"license": "MIT", | ||
"homepage": "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
Made by: Jiab77 <https://github.com/Jiab77/libvirt-web> | ||
Based on: | ||
- https://developer.mozilla.org/en-US/docs/Learn/Server-side/Node_server_without_framework | ||
- https://blog.bloomca.me/2018/12/22/writing-a-web-server-node.html | ||
- https://nodejs.org/en/docs/guides/getting-started-guide/ | ||
- https://www.w3schools.com/nodejs/nodejs_http.asp | ||
*/ | ||
|
||
"use strict"; | ||
|
||
const http = require('http'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const process = require('process'); | ||
const hostname = process.env.LIBVIRT_WEB_HOST || '127.0.0.1'; | ||
const port = process.env.LIBVIRT_WEB_PORT || 8001; | ||
|
||
http.createServer(function (request, response) { | ||
const url = request.url; | ||
|
||
console.log('[Info] Requested:', url); | ||
|
||
var filePath = '.' + url; | ||
if (filePath == './') { | ||
filePath = './index.html'; | ||
} | ||
|
||
var extname = String(path.extname(filePath)).toLowerCase(); | ||
var mimeTypes = { | ||
'.html': 'text/html', | ||
'.js': 'text/javascript', | ||
'.css': 'text/css', | ||
'.json': 'application/json', | ||
'.png': 'image/png', | ||
'.jpg': 'image/jpg', | ||
'.gif': 'image/gif', | ||
'.svg': 'image/svg+xml', | ||
'.wav': 'audio/wav', | ||
'.mp4': 'video/mp4', | ||
'.woff': 'application/font-woff', | ||
'.ttf': 'application/font-ttf', | ||
'.eot': 'application/vnd.ms-fontobject', | ||
'.otf': 'application/font-otf', | ||
'.wasm': 'application/wasm' | ||
}; | ||
|
||
var contentType = mimeTypes[extname] || 'application/octet-stream'; | ||
|
||
// Serve static files | ||
fs.readFile(filePath, function(error, content) { | ||
if (error) { | ||
console.error(error); | ||
|
||
if(error.code == 'ENOENT') { | ||
fs.readFile('./static-404.html', function(error, content) { | ||
if (error) { | ||
console.error(error); | ||
} | ||
else { | ||
response.writeHead(404, { 'Content-Type': 'text/html' }); | ||
response.end(content, 'utf-8'); | ||
|
||
// log served response | ||
console.log('[Info] Served static 404 page.'); | ||
} | ||
}); | ||
} | ||
else { | ||
response.writeHead(500); | ||
response.end('Sorry, check with the site admin for error: '+error.code+' ...\n'); | ||
} | ||
|
||
// log served response | ||
console.log('[Info] Could not serve:', url); | ||
} | ||
else { | ||
response.writeHead(200, { 'Content-Type': contentType }); | ||
response.end(content, 'utf-8'); | ||
|
||
// log served response | ||
console.log('[Info] Served:', url); | ||
} | ||
}); | ||
|
||
}).listen(port, hostname, () => { | ||
console.log(`Server running at http://${hostname}:${port}/`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<!-- Standard Meta --> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"> | ||
|
||
<!-- Site Properties --> | ||
<title>Fomantic UI – Error 404</title> | ||
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.css"> | ||
|
||
<!-- Custom CSS --> | ||
<link rel="stylesheet" type="text/css" href="static.css"> | ||
|
||
<!-- Custom Style --> | ||
<style type="text/css"></style> | ||
</head> | ||
<body> | ||
<!-- Top Following Menu --> | ||
<div class="ui top fixed menu transition hidden"> | ||
<div class="ui fluid container"> | ||
<div class="header link item"><a href="index.html"><i class="cubes icon"></i>libVirt Web</a></div> | ||
<div class="right menu"> | ||
<div class="ui item animated labeled icon button" id="dark-theme"> | ||
<div class="visible content"> | ||
<i class="moon icon"></i> | ||
Dark | ||
</div> | ||
<div class="hidden content"> | ||
<i class="sun icon"></i> | ||
Light | ||
</div> | ||
</div> | ||
<div class="ui item animated labeled icon button" id="light-theme"> | ||
<div class="visible content"> | ||
<i class="sun icon"></i> | ||
Light | ||
</div> | ||
<div class="hidden content"> | ||
<i class="moon icon"></i> | ||
Dark | ||
</div> | ||
</div> | ||
<!-- <div class="ui dropdown item"> | ||
<i class="home icon"></i> | ||
Menu | ||
<i class="dropdown icon"></i> | ||
<div class="menu"> | ||
<a href="dashboard.html" class="item"><i class="chart pie icon"></i>Dashboard</a> | ||
<a href="index.html" class="item active"><i class="grip horizontal icon"></i>Modules</a> | ||
<a href="help.html" class="item"><i class="question circle outline icon"></i>Help</a> | ||
<a class="item"><i class="redo icon"></i>Refresh</a> | ||
</div> | ||
</div> | ||
<div class="ui dropdown item"> | ||
<i class="cog icon"></i> | ||
Settings | ||
<i class="dropdown icon"></i> | ||
<div class="menu"> | ||
<a class="item"><i class="us flag"></i>English</a> | ||
<a class="item"><i class="fr flag"></i>French</a> | ||
<a class="item"><i class="ru flag"></i>Russian</a> | ||
<a class="item"><i class="es flag"></i>Spanish</a> | ||
<a class="item"><i class="ch flag"></i>Swiss French</a> | ||
</div> | ||
</div> --> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<!-- Sidebar Menu --> | ||
<div class="ui left inverted sidebar vertical menu"> | ||
<div class="header link item"> | ||
<a href="index.html"> | ||
<i class="cubes icon" style="float: left; margin: 0 0.35714286em 0 0;"></i> | ||
libVirt Web | ||
</a> | ||
</div> | ||
<a href="static-dashboard.html" class="item"> | ||
<i class="chart pie icon" style="float: left; margin: 0 0.35714286em 0 0;"></i> | ||
Dashboard | ||
</a> | ||
<a href="index.html" class="item active"> | ||
<i class="grip horizontal icon" style="float: left; margin: 0 0.35714286em 0 0;"></i> | ||
Modules | ||
</a> | ||
<a href="static-help.html" class="item"> | ||
<i class="question circle outline icon" style="float: left; margin: 0 0.35714286em 0 0;"></i> | ||
Help | ||
</a> | ||
<a class="item"> | ||
<i class="redo icon" style="float: left; margin: 0 0.35714286em 0 0;"></i> | ||
Refresh | ||
</a> | ||
<div class="item"> | ||
<div class="ui inverted accordion"> | ||
<div class="title"> | ||
<i class="cog icon" style="float: left;"></i> | ||
Settings | ||
<i class="dropdown icon" style="float: right;"></i> | ||
</div> | ||
<div class="content"> | ||
<div class="ui vertical inverted menu"> | ||
<a class="item"><i class="us flag"></i>English</a> | ||
<a class="item"><i class="fr flag"></i>French</a> | ||
<a class="item"><i class="ru flag"></i>Russian</a> | ||
<a class="item"><i class="es flag"></i>Spanish</a> | ||
<a class="item"><i class="ch flag"></i>Swiss French</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<!-- Page Contents --> | ||
<div class="pusher"> | ||
<!-- Top Static Menu --> | ||
<header class="ui inverted vertical segment"> | ||
<div class="ui fluid container"> | ||
<div class="ui large secondary inverted menu"> | ||
<a class="toc item"><i class="sidebar icon"></i></a> | ||
<div class="header link item large screen only"><a href="index.html"><i class="cubes icon"></i>libVirt Web</a></div> | ||
<div class="header link item center aligned mobile only"><a href="index.html"><i class="cubes icon"></i>libVirt Web</a></div> | ||
<div class="right menu"> | ||
<div class="ui item animated labeled icon button" id="dark-theme"> | ||
<div class="visible content"> | ||
<i class="moon icon"></i> | ||
Dark | ||
</div> | ||
<div class="hidden content"> | ||
<i class="sun icon"></i> | ||
Light | ||
</div> | ||
</div> | ||
<div class="ui item animated labeled icon button" id="light-theme"> | ||
<div class="visible content"> | ||
<i class="sun icon"></i> | ||
Light | ||
</div> | ||
<div class="hidden content"> | ||
<i class="moon icon"></i> | ||
Dark | ||
</div> | ||
</div> | ||
<a href="static-dashboard.html" class="item"><i class="chart pie icon"></i>Dashboard</a> | ||
<a href="index.html" class="item active"><i class="grip horizontal icon"></i>Modules</a> | ||
<a href="static-help.html" class="item"><i class="question circle outline icon"></i>Help</a> | ||
<a class="item"><i class="redo icon"></i>Refresh</a> | ||
<div class="ui inverted dropdown item"> | ||
<i class="cog icon"></i> Settings <i class="dropdown icon"></i> | ||
<div class="menu"> | ||
<a class="item"><i class="us flag"></i>English</a> | ||
<a class="item"><i class="fr flag"></i>French</a> | ||
<a class="item"><i class="ru flag"></i>Russian</a> | ||
<a class="item"><i class="es flag"></i>Spanish</a> | ||
<a class="item"><i class="ch flag"></i>Swiss French</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</header> | ||
|
||
<!-- Main content--> | ||
<main class="ui vertical basic very padded segment"> | ||
<div id="variable-container" class="ui container"> | ||
<h2 class="ui dividing header">Error 404</h2> | ||
<p>Resource not found.</p> | ||
</div> | ||
</main> | ||
|
||
<!-- Footer --> | ||
<footer class="ui inverted vertical footer segment"> | ||
<div class="ui container"> | ||
<div class="ui stackable inverted divided equal height grid"> | ||
<div class="ten wide column"> | ||
<h4 class="ui inverted header"><i class="cubes icon"></i>libVirt Web</h4> | ||
<p>A simple web interface based on <a href="https://libvirt.org/" target="_blank">libVirt</a> and <a href="http://libguestfs.org/" target="_blank">libguestfs</a>.</p> | ||
</div> | ||
<div class="three wide column"> | ||
<h4 class="ui inverted header">About</h4> | ||
<div class="ui inverted link list"> | ||
<a class="item" href="https://github.com/Jiab77/libvirt-web" target="_blank">Project</a> | ||
<a class="item" href="#!">Documentation</a> | ||
</div> | ||
</div> | ||
<div class="three wide column"> | ||
<h4 class="ui inverted header">Credits</h4> | ||
<div class="ui inverted link list"> | ||
<a class="item" href="https://libvirt.org/" target="_blank">libVirt</a> | ||
<a class="item" href="http://libguestfs.org/" target="_blank">libguestfs</a> | ||
<a class="item" href="https://fomantic-ui.com/" target="_blank">Fomantic-UI</a> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="ui section divider"></div> | ||
<div class="ui horizontal inverted divided link list"> | ||
<div class="item"> | ||
<span>© 2020 - </span> | ||
<a href="https://github.com/Jiab77" target="_blank">Jiab77</a> | ||
</div> | ||
</div> | ||
</div> | ||
</footer> | ||
</div> | ||
|
||
<!-- Fomantic-UI --> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.js"></script> | ||
<script src="static.js"></script> | ||
</body> | ||
</html> |