-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move webui to base url
/_expo/atlas
(#16)
* refactor: move webui to base url `/_expo/atlas` * refactor: serve atlas on base url through cli * refactor: temporarily switch to patched `expo-router` for base url support
- Loading branch information
Showing
10 changed files
with
38 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,25 @@ | ||
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 { env } from '../utils/env'; | ||
import { CLIENT_BUILD_DIR, SERVER_BUILD_DIR } from '../utils/middleware'; | ||
import { createAtlasMiddleware } from '../utils/middleware'; | ||
|
||
export function createServer(options: Options) { | ||
global.EXPO_ATLAS_SOURCE = new StatsFileSource(options.statsFile); | ||
process.env.NODE_ENV = 'production'; | ||
|
||
const app = express(); | ||
const source = new StatsFileSource(options.statsFile); | ||
const middleware = createAtlasMiddleware(source); | ||
const baseUrl = '/_expo/atlas'; // Keep in sync with webui `app.json` `baseUrl` | ||
|
||
// http://expressjs.com/en/advanced/best-practice-security.html#at-a-minimum-disable-x-powered-by-header | ||
app.disable('x-powered-by'); | ||
const app = express(); | ||
|
||
app.disable('x-powered-by'); // http://expressjs.com/en/advanced/best-practice-security.html#at-a-minimum-disable-x-powered-by-header | ||
app.use(compression()); | ||
app.use(baseUrl, middleware); | ||
|
||
if (env.EXPO_ATLAS_DEBUG) { | ||
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 })); | ||
// Add catch-all to redirect to the webui | ||
app.use((req, res, next) => (!req.url.startsWith(baseUrl) ? res.redirect(baseUrl) : next())); | ||
|
||
return app; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Keep this path in sync with `app.json`'s `baseUrl`. | ||
* | ||
* @see https://docs.expo.dev/versions/latest/config/app/#baseurl | ||
*/ | ||
const baseUrl = '/_expo/atlas'; | ||
|
||
/** | ||
* Fetch data from the API routes, adding the `baseUrl` to all requests. | ||
*/ | ||
export function fetchApi(path: string, options?: RequestInit) { | ||
if (path.startsWith(baseUrl)) { | ||
return fetch(path, options); | ||
} | ||
|
||
return fetch(path.startsWith('/') ? `${baseUrl}${path}` : `${baseUrl}/${path}`, options); | ||
} |