Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: decoupled video config #306

Merged
merged 10 commits into from
Oct 28, 2024
Merged

feat: decoupled video config #306

merged 10 commits into from
Oct 28, 2024

Conversation

luwes
Copy link
Collaborator

@luwes luwes commented Oct 9, 2024

fix #304
related #281

This change adds a video config that is decoupled (not stored) in the Next runtime config which allows us to store complex objects like functions. It's a similar pattern that next-auth uses.

The old pattern of adding the video config to next.config.js still works for processing local assets but remote assets will require adding a next-video.(js|mjs) file with the video config. This file will export some functions that can then be used in the video API routes.

for example:

// next-video.mjs
import { NextVideo } from 'next-video/process';
import { readFile } from 'fs/promises';

export const { GET, POST, handler, withNextVideo } = NextVideo({
  loadAsset: async function (assetPath) {
    console.warn(99, assetPath);
    const file = await readFile(assetPath);
    const asset = JSON.parse(file.toString());
    return asset;
  },
});

withNextVideo is exported as well so devs don't need to duplicate the video config.

// next.config.mjs
import { withNextVideo } from './next-video.mjs';

/** @type {import('next').NextConfig} */
const nextConfig = (phase, { defaultConfig }) => {
  return {
    ...defaultConfig,
  };
};

export default withNextVideo(nextConfig);

In this file devs will be able to add auth or other access control.

// api/video/route.js
export { GET, POST } from '@/next-video';

The processing on a GET request if the file is not processed yet is removed.
This requires an explicit POST request now to
e.g. /api/video?url=https://storage.googleapis.com/muxdemofiles/mux.mp4

Copy link

vercel bot commented Oct 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-video-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 28, 2024 7:50pm

@codecov-commenter
Copy link

codecov-commenter commented Oct 9, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 32 lines in your changes missing coverage. Please review.

Project coverage is 88.09%. Comparing base (a3951a3) to head (ae75ae7).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/request-handler.ts 50.90% 27 Missing ⚠️
src/setup-next-video.ts 75.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #306      +/-   ##
==========================================
- Coverage   90.67%   88.09%   -2.59%     
==========================================
  Files          30       32       +2     
  Lines        2456     2562     +106     
  Branches      350      285      -65     
==========================================
+ Hits         2227     2257      +30     
- Misses        228      304      +76     
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@luwes luwes changed the title example: try setting callback / hook in config feat: decoupled video config Oct 14, 2024
@luwes luwes marked this pull request as ready for review October 21, 2024 18:37
Copy link
Contributor

@mmcc mmcc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the CLI create/write this file on init now? Docs updates?

README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@luwes luwes merged commit e0b426c into muxinc:main Oct 28, 2024
8 checks passed
@luwes luwes deleted the config-function-bug branch October 28, 2024 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vercel does not support functions inside next.config.js
4 participants