Skip to content

Commit

Permalink
Render application shell as static file
Browse files Browse the repository at this point in the history
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 efff579
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -29,4 +29,5 @@ build/public/*
!build/public/favicon.ico
!build/public/favicon.png
!build/public/robots.txt
!build/public/index.html
build/server
4 changes: 2 additions & 2 deletions build/views/index.ejs → build/public/index.html
@@ -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"/>
Expand Down
20 changes: 7 additions & 13 deletions server/routes/index.ts
@@ -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;
6 changes: 1 addition & 5 deletions server/server.ts
Expand Up @@ -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;
Expand Down

0 comments on commit efff579

Please sign in to comment.