add web asset processing via webpack
This commit is contained in:
parent
ce39720c0f
commit
efaf3d9d95
|
@ -1,3 +1,3 @@
|
||||||
|
/node_modules
|
||||||
/target
|
/target
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
{
|
||||||
|
"name": "garbage-pile",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A Verifying OpenPGP Key Server",
|
||||||
|
"main": "",
|
||||||
|
"scripts": {
|
||||||
|
"build": "webpack",
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+ssh://git@gitlab.com/sequoia-pgp/garbage-pile.git"
|
||||||
|
},
|
||||||
|
"author": "kai@sequoia-pgp.org",
|
||||||
|
"license": "GPL-3.0",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://gitlab.com/sequoia-pgp/garbage-pile/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://gitlab.com/sequoia-pgp/garbage-pile#README",
|
||||||
|
"dependencies": {
|
||||||
|
"bootstrap": "^4.1.3",
|
||||||
|
"jquery": "^3.3.1",
|
||||||
|
"popper.js": "^1.14.4"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"autoprefixer": "^9.2.1",
|
||||||
|
"bootswatch": "^4.1.3",
|
||||||
|
"copy-webpack-plugin": "^4.5.3",
|
||||||
|
"css-loader": "^1.0.0",
|
||||||
|
"extract-text-webpack-plugin": "^4.0.0-beta.0",
|
||||||
|
"html-webpack-plugin": "^3.2.0",
|
||||||
|
"node-sass": "^4.9.4",
|
||||||
|
"postcss-loader": "^3.0.0",
|
||||||
|
"sass-loader": "^7.1.0",
|
||||||
|
"style-loader": "^0.23.1",
|
||||||
|
"webpack": "^4.21.0",
|
||||||
|
"webpack-cli": "^3.1.2"
|
||||||
|
}
|
||||||
|
}
|
|
@ -57,9 +57,6 @@ pub struct Opt {
|
||||||
/// Base directory
|
/// Base directory
|
||||||
#[structopt(parse(from_os_str))]
|
#[structopt(parse(from_os_str))]
|
||||||
base: PathBuf,
|
base: PathBuf,
|
||||||
/// Template directory
|
|
||||||
#[structopt(parse(from_os_str))]
|
|
||||||
templates: PathBuf,
|
|
||||||
/// Port and address to listen on.
|
/// Port and address to listen on.
|
||||||
#[structopt(short = "l", long = "listen", default_value = "0.0.0.0:8080")]
|
#[structopt(short = "l", long = "listen", default_value = "0.0.0.0:8080")]
|
||||||
listen: String,
|
listen: String,
|
||||||
|
@ -75,10 +72,6 @@ fn main() {
|
||||||
panic!("Base directory must be absolute");
|
panic!("Base directory must be absolute");
|
||||||
}
|
}
|
||||||
|
|
||||||
if !opt.templates.is_absolute() {
|
|
||||||
panic!("Template directory must be absolute");
|
|
||||||
}
|
|
||||||
|
|
||||||
let db = Filesystem::new(opt.base.clone()).unwrap();
|
let db = Filesystem::new(opt.base.clone()).unwrap();
|
||||||
web::serve(&opt, Polymorphic::Filesystem(db)).unwrap();
|
web::serve(&opt, Polymorphic::Filesystem(db)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
use rocket;
|
use rocket;
|
||||||
use rocket::Outcome;
|
use rocket::{State, Outcome};
|
||||||
use rocket::http::Status;
|
use rocket::http::Status;
|
||||||
use rocket::request::{self, Request, FromRequest};
|
use rocket::request::{self, Request, FromRequest};
|
||||||
use rocket::response::content;
|
use rocket::response::content;
|
||||||
use rocket::response::status::Custom;
|
use rocket::response::status::Custom;
|
||||||
use rocket::http::uri::URI;
|
use rocket::http::uri::URI;
|
||||||
|
use rocket::response::NamedFile;
|
||||||
|
use rocket::fairing::AdHoc;
|
||||||
|
|
||||||
use rocket_contrib::Template;
|
use rocket_contrib::Template;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
mod upload;
|
mod upload;
|
||||||
|
|
||||||
|
@ -47,6 +50,8 @@ mod templates {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct StaticDir(String);
|
||||||
|
|
||||||
impl<'a, 'r> FromRequest<'a, 'r> for queries::Key {
|
impl<'a, 'r> FromRequest<'a, 'r> for queries::Key {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
|
|
||||||
|
@ -190,6 +195,11 @@ fn confirm(db: rocket::State<Polymorphic>, token: String)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/static/<file..>")]
|
||||||
|
fn files(file: PathBuf, static_dir: State<StaticDir>) -> Option<NamedFile> {
|
||||||
|
NamedFile::open(Path::new(&static_dir.0).join(file)).ok()
|
||||||
|
}
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn root() -> Template {
|
fn root() -> Template {
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
@ -220,7 +230,8 @@ pub fn serve(opt: &Opt, db: Polymorphic) -> Result<()> {
|
||||||
.port(port)
|
.port(port)
|
||||||
.workers(2)
|
.workers(2)
|
||||||
.root(opt.base.join("public"))
|
.root(opt.base.join("public"))
|
||||||
.extra("template_dir", format!("{}", opt.templates.display()))
|
.extra("template_dir", format!("{}/templates", opt.base.display()))
|
||||||
|
.extra("static_dir", format!("{}/public", opt.base.display()))
|
||||||
.finalize()?;
|
.finalize()?;
|
||||||
let routes = routes![
|
let routes = routes![
|
||||||
upload::multipart_upload,
|
upload::multipart_upload,
|
||||||
|
@ -228,11 +239,20 @@ pub fn serve(opt: &Opt, db: Polymorphic) -> Result<()> {
|
||||||
verify,
|
verify,
|
||||||
delete,
|
delete,
|
||||||
confirm,
|
confirm,
|
||||||
root
|
root,
|
||||||
|
files,
|
||||||
];
|
];
|
||||||
|
|
||||||
rocket::custom(config, opt.verbose)
|
rocket::custom(config, opt.verbose)
|
||||||
.attach(Template::fairing())
|
.attach(Template::fairing())
|
||||||
|
.attach(AdHoc::on_attach(|rocket| {
|
||||||
|
let static_dir = rocket.config()
|
||||||
|
.get_str("static_dir")
|
||||||
|
.unwrap()
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
Ok(rocket.manage(StaticDir(static_dir)))
|
||||||
|
}))
|
||||||
.mount("/", routes)
|
.mount("/", routes)
|
||||||
.manage(db)
|
.manage(db)
|
||||||
.launch();
|
.launch();
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
<!doctype html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Garbage Pile Public Key Server</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
{{> @partial-block }}
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,6 +1,6 @@
|
||||||
{{#> layout }}
|
{{#> layout }}
|
||||||
<h1>Garbage Pile Public Key Server</h1>
|
<h1 class="mt-5">Garbage Pile Public Key Server</h1>
|
||||||
<p>The verifying PGP key server. Powered by p≡pnology!
|
<p class="lead">The verifying PGP key server. Powered by p≡pnology!
|
||||||
|
|
||||||
<h2>Search for keys</h2>
|
<h2>Search for keys</h2>
|
||||||
<form action="/search" method=POST>
|
<form action="/search" method=POST>
|
|
@ -0,0 +1,2 @@
|
||||||
|
import 'bootstrap';
|
||||||
|
import './index.scss';
|
|
@ -0,0 +1,3 @@
|
||||||
|
@import "~bootswatch/dist/simplex/variables";
|
||||||
|
@import "~bootstrap/scss/bootstrap";
|
||||||
|
@import "~bootswatch/dist/simplex/bootswatch";
|
|
@ -0,0 +1,57 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
|
|
||||||
|
<title>Garbage Pile Public Key Server</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||||
|
<a class="navbar-brand" href="#">Navbar</a>
|
||||||
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||||
|
<ul class="navbar-nav mr-auto">
|
||||||
|
<li class="nav-item active">
|
||||||
|
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="#">Link</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item dropdown">
|
||||||
|
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
|
Dropdown
|
||||||
|
</a>
|
||||||
|
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||||
|
<a class="dropdown-item" href="#">Action</a>
|
||||||
|
<a class="dropdown-item" href="#">Another action</a>
|
||||||
|
<div class="dropdown-divider"></div>
|
||||||
|
<a class="dropdown-item" href="#">Something else here</a>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link disabled" href="#">Disabled</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<form class="form-inline my-2 my-lg-0">
|
||||||
|
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
|
||||||
|
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col"></div>
|
||||||
|
<div class="col-md-10">
|
||||||
|
{{> @partial-block }}
|
||||||
|
</div>
|
||||||
|
<div class="col"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,55 @@
|
||||||
|
const path = require('path');
|
||||||
|
const html = require('html-webpack-plugin');
|
||||||
|
const text = require('extract-text-webpack-plugin');
|
||||||
|
const copy = require('copy-webpack-plugin')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
mode: 'production',
|
||||||
|
entry: './web/index.js',
|
||||||
|
output: {
|
||||||
|
filename: 'site.js',
|
||||||
|
path: path.resolve(__dirname, 'dist', 'public'),
|
||||||
|
publicPath: '/static'
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test:/\.(s*)css$/,
|
||||||
|
use: text.extract({
|
||||||
|
fallback: 'style-loader',
|
||||||
|
use: [
|
||||||
|
'css-loader',
|
||||||
|
'sass-loader',
|
||||||
|
{
|
||||||
|
loader: 'postcss-loader',
|
||||||
|
options: {
|
||||||
|
plugins: function () { // post css plugins, can be exported to postcss.config.js
|
||||||
|
return [
|
||||||
|
require('autoprefixer')
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new html({
|
||||||
|
filename: '../templates/layout.html.hbs',
|
||||||
|
template: 'web/layout.html.hbs',
|
||||||
|
}),
|
||||||
|
new text({
|
||||||
|
filename: 'site.css'
|
||||||
|
}),
|
||||||
|
new copy([
|
||||||
|
{
|
||||||
|
from: 'web/*.html.hbs',
|
||||||
|
to: path.resolve(__dirname, 'dist', "templates"),
|
||||||
|
ignore: [ 'layout.html.hbs' ],
|
||||||
|
flatten: true
|
||||||
|
}
|
||||||
|
])
|
||||||
|
]
|
||||||
|
};
|
Loading…
Reference in New Issue