Skip to content

Commit

Permalink
refactor: revert cli server to express only
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric committed Mar 16, 2024
1 parent b7a236b commit ba8cac1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/cli/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import arg from 'arg';
import open from 'open';
import path from 'path';

import { createServer } from './createServer';
import { resolveOptions } from './resolveOptions';
import { createServer } from './server';

export type Input = typeof args;

Expand Down
34 changes: 34 additions & 0 deletions src/cli/createServer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { createRequestHandler } from '@expo/server/adapter/express';
import compression from 'compression';
import express from 'express';
import morgan from 'morgan';

import { type Options } from './resolveOptions';
import { StatsFileSource } from '../data/StatsFileSource';
import { CLIENT_BUILD_DIR, SERVER_BUILD_DIR } from '../utils/middleware';

export function createServer(options: Options) {
global.EXPO_ATLAS_SOURCE = new StatsFileSource(options.statsFile);
process.env.NODE_ENV = 'production';

const app = express();

// http://expressjs.com/en/advanced/best-practice-security.html#at-a-minimum-disable-x-powered-by-header
app.disable('x-powered-by');

app.use(compression());
app.use(morgan('tiny'));

// TODO(cedric): replace with middleware once we can
app.use(
express.static(CLIENT_BUILD_DIR, {
maxAge: '1h',
extensions: ['html'],
})
);

// TODO(cedric): replace with middleware once we can
app.all('*', createRequestHandler({ build: SERVER_BUILD_DIR }));

return app;
}
22 changes: 0 additions & 22 deletions src/cli/server.ts

This file was deleted.

6 changes: 4 additions & 2 deletions src/utils/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import { env } from './env';
import { type StatsSource } from '../data/types';

const WEBUI_ROOT = path.resolve(__dirname, '../../../webui');
const CLIENT_BUILD_DIR = path.join(WEBUI_ROOT, 'dist/client');
const SERVER_BUILD_DIR = path.join(WEBUI_ROOT, 'dist/server');

// TODO(cedric): drop these exports once we can use this as base for the standalone server
export const CLIENT_BUILD_DIR = path.join(WEBUI_ROOT, 'dist/client');
export const SERVER_BUILD_DIR = path.join(WEBUI_ROOT, 'dist/server');

/**
* Initialize Expo Atlas to gather statistics from Metro during development.
Expand Down
3 changes: 1 addition & 2 deletions webui/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
},
"experiments": {
"tsconfigPaths": true,
"typedRoutes": true,
"baseUrl": "/_expo/atlas"
"typedRoutes": true
},
"plugins": [
"expo-router"
Expand Down

0 comments on commit ba8cac1

Please sign in to comment.