@@ -272,41 +272,46 @@ app.get("/:locale/blog/author/:slug/:asset", async (req, res) => {
272
272
)
273
273
) . pipe ( res ) ;
274
274
} ) ;
275
- app . get ( "/:locale/blog/:slug/index.json" , async ( req , res ) => {
276
- const { slug } = req . params ;
277
- const data = await findPostBySlug ( slug ) ;
278
- if ( ! data ) {
275
+ if ( BLOG_ROOT ) {
276
+ app . get ( "/:locale/blog/:slug/index.json" , async ( req , res ) => {
277
+ const { slug } = req . params ;
278
+ const data = await findPostBySlug ( slug ) ;
279
+ if ( ! data ) {
280
+ return res . status ( 404 ) . send ( "Nothing here 🤷♂️" ) ;
281
+ }
282
+ return res . json ( data ) ;
283
+ } ) ;
284
+ app . get (
285
+ [ "/:locale/blog/:slug/runner.html" , "/:locale/blog/:slug/runner.html" ] ,
286
+ async ( req , res ) => {
287
+ return res
288
+ . setHeader ( "Content-Security-Policy" , PLAYGROUND_UNSAFE_CSP_VALUE )
289
+ . status ( 200 )
290
+ . sendFile ( path . join ( STATIC_ROOT , "runner.html" ) ) ;
291
+ }
292
+ ) ;
293
+ app . get ( "/:locale/blog/:slug/_sample_.:id.html" , async ( req , res ) => {
294
+ const { slug, id } = req . params ;
295
+ try {
296
+ return res . send ( await findPostLiveSampleBySlug ( slug , id ) ) ;
297
+ } catch ( e ) {
298
+ return res . status ( 404 ) . send ( e . toString ( ) ) ;
299
+ }
300
+ } ) ;
301
+ app . get ( "/:locale/blog/:slug/:asset" , async ( req , res ) => {
302
+ const { slug, asset } = req . params ;
303
+ const p = findPostPathBySlug ( slug ) ;
304
+ if ( p ) {
305
+ return send (
306
+ req ,
307
+ path . resolve ( path . join ( p , sanitizeFilename ( asset ) ) )
308
+ ) . pipe ( res ) ;
309
+ }
279
310
return res . status ( 404 ) . send ( "Nothing here 🤷♂️" ) ;
280
- }
281
- return res . json ( data ) ;
282
- } ) ;
283
- app . get (
284
- [ "/:locale/blog/:slug/runner.html" , "/:locale/blog/:slug/runner.html" ] ,
285
- async ( req , res ) => {
286
- return res
287
- . setHeader ( "Content-Security-Policy" , PLAYGROUND_UNSAFE_CSP_VALUE )
288
- . status ( 200 )
289
- . sendFile ( path . join ( STATIC_ROOT , "runner.html" ) ) ;
290
- }
291
- ) ;
292
- app . get ( "/:locale/blog/:slug/_sample_.:id.html" , async ( req , res ) => {
293
- const { slug, id } = req . params ;
294
- try {
295
- return res . send ( await findPostLiveSampleBySlug ( slug , id ) ) ;
296
- } catch ( e ) {
297
- return res . status ( 404 ) . send ( e . toString ( ) ) ;
298
- }
299
- } ) ;
300
- app . get ( "/:locale/blog/:slug/:asset" , async ( req , res ) => {
301
- const { slug, asset } = req . params ;
302
- const p = findPostPathBySlug ( slug ) ;
303
- if ( p ) {
304
- return send ( req , path . resolve ( path . join ( p , sanitizeFilename ( asset ) ) ) ) . pipe (
305
- res
306
- ) ;
307
- }
308
- return res . status ( 404 ) . send ( "Nothing here 🤷♂️" ) ;
309
- } ) ;
311
+ } ) ;
312
+ } else {
313
+ console . warn ( "'BLOG_ROOT' not set in .env file" ) ;
314
+ }
310
315
app . get ( "/*" , async ( req , res , ...args ) => {
311
316
const parsedUrl = new URL ( req . url , `http://localhost:${ PORT } ` ) ;
312
317
if ( req . url . startsWith ( "/_" ) ) {
0 commit comments