webpacked the heck out of the build
This commit is contained in:
parent
0ab8ddc894
commit
757ac14d1a
16 changed files with 838 additions and 97 deletions
|
@ -9,8 +9,7 @@ const storage = require('./storage.js');
|
|||
const Raven = require('raven');
|
||||
const crypto = require('crypto');
|
||||
const fs = require('fs');
|
||||
const version = require('../dist/version.json');
|
||||
const assets = require('../dist/manifest.json');
|
||||
const version = require('../dist/public/version.json');
|
||||
|
||||
if (conf.sentry_dsn) {
|
||||
Raven.config(conf.sentry_dsn).install();
|
||||
|
@ -20,7 +19,7 @@ const mozlog = require('./log.js');
|
|||
|
||||
const log = mozlog('send.server');
|
||||
|
||||
const STATIC_PATH = path.join(__dirname, '../dist');
|
||||
const STATIC_PATH = path.join(__dirname, '../dist/public');
|
||||
|
||||
const app = express();
|
||||
|
||||
|
@ -37,37 +36,30 @@ function prodLangs() {
|
|||
return require('../package.json').availableLanguages.join(',');
|
||||
}
|
||||
|
||||
let asset = name => assets[name];
|
||||
|
||||
const availableLanguages = conf.l10n_dev ? allLangs() : prodLangs();
|
||||
|
||||
if (conf.env === 'development') {
|
||||
const webpack = require('webpack');
|
||||
const webpackDevMiddleware = require('webpack-dev-middleware');
|
||||
const config = require('../webpack.config.js');
|
||||
config.devtool = 'inline-source-map';
|
||||
const compiler = webpack(config);
|
||||
const wdm = webpackDevMiddleware(compiler, {
|
||||
publicPath: config.output.publicPath
|
||||
});
|
||||
app.use(wdm);
|
||||
asset = name => {
|
||||
const f = wdm.fileSystem.readFileSync(
|
||||
wdm.getFilenameFromUrl('/manifest.json')
|
||||
);
|
||||
return JSON.parse(f)[name];
|
||||
};
|
||||
}
|
||||
// dev middleware is broken at the moment because of how webpack builds the
|
||||
// handlebars templates. Leaving the commented code here as a mark of shame.
|
||||
|
||||
// if (conf.env === 'development') {
|
||||
// const webpack = require('webpack');
|
||||
// const webpackDevMiddleware = require('webpack-dev-middleware');
|
||||
// const config = require('../webpack.config.js');
|
||||
// config.devtool = 'inline-source-map';
|
||||
// const compiler = webpack(config);
|
||||
// const wdm = webpackDevMiddleware(compiler, {
|
||||
// publicPath: config.output.publicPath
|
||||
// });
|
||||
// app.use(wdm);
|
||||
// }
|
||||
app.set('views', 'dist/views/');
|
||||
app.engine(
|
||||
'handlebars',
|
||||
exphbs({
|
||||
defaultLayout: 'main',
|
||||
partialsDir: 'views/partials/',
|
||||
layoutsDir: 'dist/views/layouts',
|
||||
helpers: {
|
||||
asset,
|
||||
availableLanguages,
|
||||
l10nDev: conf.l10n_dev,
|
||||
baseUrl: conf.base_url,
|
||||
title: 'Firefox Send',
|
||||
description:
|
||||
|
@ -112,6 +104,14 @@ app.use(
|
|||
})
|
||||
);
|
||||
app.use(bodyParser.json());
|
||||
app.use(
|
||||
'/resources',
|
||||
express.static(path.join(STATIC_PATH, 'resources'), {
|
||||
setHeaders: function(res) {
|
||||
res.set('Cache-Control', 'public, max-age=31536000, immutable');
|
||||
}
|
||||
})
|
||||
);
|
||||
app.use(express.static(STATIC_PATH));
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue