Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and astrobot-houston committed Nov 9, 2022
1 parent dca762c commit 92374c0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
5 changes: 2 additions & 3 deletions packages/astro/src/vite-plugin-astro-server/base.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type * as vite from 'vite';
import type { AstroSettings } from '../@types/astro';

import * as fs from 'fs';
import { LogOptions } from '../core/logger/core.js';
import notFoundTemplate, { subpathNotUsedTemplate } from '../template/4xx.js';
import { log404 } from './common.js';
import { writeHtmlResponse } from './response.js';
import * as fs from 'fs';

export function baseMiddleware(
settings: AstroSettings,
Expand All @@ -20,7 +20,6 @@ export function baseMiddleware(

const pathname = decodeURI(new URL(url, 'https://localhost').pathname);


if (pathname.startsWith(devRoot)) {
req.url = url.replace(devRoot, '/');
return next();
Expand All @@ -46,7 +45,7 @@ export function baseMiddleware(
// Check to see if it's in public and if so 404
const publicPath = new URL('.' + req.url, config.publicDir);
fs.stat(publicPath, (_err, stats) => {
if(stats) {
if (stats) {
log404(logging, pathname);
const html = subpathNotUsedTemplate(devRoot, pathname);
return writeHtmlResponse(res, 404, html);
Expand Down
49 changes: 26 additions & 23 deletions packages/astro/test/units/dev/dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,34 +159,37 @@ describe('dev container', () => {
});

it('items in public/ are not available from root when using a base', async () => {
await runInContainer({
root,
userConfig: {
base: '/sub/'
}
}, async (container) => {
// First try the subpath
let r = createRequestAndResponse({
method: 'GET',
url: '/sub/test.txt',
});
await runInContainer(
{
root,
userConfig: {
base: '/sub/',
},
},
async (container) => {
// First try the subpath
let r = createRequestAndResponse({
method: 'GET',
url: '/sub/test.txt',
});

container.handle(r.req, r.res);
await r.done;
container.handle(r.req, r.res);
await r.done;

expect(r.res.statusCode).to.equal(200);
expect(r.res.statusCode).to.equal(200);

// Next try the root path
r = createRequestAndResponse({
method: 'GET',
url: '/test.txt',
});
// Next try the root path
r = createRequestAndResponse({
method: 'GET',
url: '/test.txt',
});

container.handle(r.req, r.res);
await r.done;
container.handle(r.req, r.res);
await r.done;

expect(r.res.statusCode).to.equal(404);
});
expect(r.res.statusCode).to.equal(404);
}
);
});

it('items in public/ are available from root when not using a base', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ describe('MDX syntax highlighting', () => {
await fixture.build();

const html = await fixture.readFile('/index.html');
expect(html).to.include('style="background-color:#000000"')
expect(html).to.include('style="background-color:#000000"');
});
});

0 comments on commit 92374c0

Please sign in to comment.