Skip to content
Permalink
Browse files

Render application shell as static file

There's no longer a need for using an EJS template, since nothing
crucial needs to be populated server-side.
  • Loading branch information...
lovett committed May 2, 2019
1 parent 7373d75 commit efff5794e453d755ebf515c894bdcb0a902306a9
Showing with 11 additions and 20 deletions.
  1. +1 −0 .gitignore
  2. +2 −2 build/{views/index.ejs → public/index.html}
  3. +7 −13 server/routes/index.ts
  4. +1 −5 server/server.ts
@@ -29,4 +29,5 @@ build/public/*
!build/public/favicon.ico
!build/public/favicon.png
!build/public/robots.txt
!build/public/index.html
build/server
@@ -1,8 +1,8 @@
<!doctype html>
<html ng-app="appModule" lang="en" ng-csp notifier-appcache-reload notifier-offline-event>
<head>
<title><%= title %></title>
<base href="<%= base_href %>" />
<title>Notifier</title>
<base href="/" />

<link rel="shortcut icon" href="favicon.png" />
<link rel="apple-touch-icon" href="app-icon.png"/>
@@ -1,24 +1,18 @@
import * as express from 'express';
import { Response } from 'express';
import PromiseRouter from 'express-promise-router';
import * as path from 'path';

const router = PromiseRouter();

/**
* The homepage is an HTML shell that loads the client-side
* application, which in turn decides which screen to display.
*
* The relative path to the HTML file is only valid for the JS version
* of this file within the build directory.
*/
router.get('/', async (req: express.Request, res: express.Response) => {
const config = req.app.locals.config;

let title = 'Notifier';
if (req.app.get('env') !== 'production') {
title += ' ' + req.app.get('env');
}

res.render('index', {
base_href: config.get('NOTIFIER_BASE_URL'),
title,
});
router.get('/', async (_, res: Response) => {
res.sendFile(path.resolve('public/index.html'));
});

export default router;
@@ -59,15 +59,11 @@ nconf.defaults({
NOTIFIER_FORCE_HTTPS: 0,
NOTIFIER_HTTP_IP: '127.0.0.1',
NOTIFIER_HTTP_PORT: 8080,
NOTIFIER_PUBLIC_DIR: path.resolve('./build/public'),
NOTIFIER_PUBLIC_DIR: path.resolve('./public'),
});

app = express();

app.set('views', path.resolve('./build/views'));

app.set('view engine', 'ejs');

app.disable('x-powered-by');

app.locals.config = nconf;

0 comments on commit efff579

Please sign in to comment.
You can’t perform that action at this time.