GithubHelp home page GithubHelp logo

Serve asset files about serve-static HOT 2 CLOSED

nestjs avatar nestjs commented on April 24, 2024 4
Serve asset files

from serve-static.

Comments (2)

wolfika avatar wolfika commented on April 24, 2024 4

@0xC0DEBA5E According to my understanding, this module is for providing an out-of-box solution for serving Single Page Applications with a built index.html, among other static assets. It's aggressively overriding / (or the URL at options.renderPath), and always looking for index.html (and if missing, throws an exception). So it's more for fully-static sites than just for static assets.

If you just want to serve some static assets (like images, CSS, etc) and not an entire SPA, I would advise you to not use this module, but a more simplistic approach, like this:

import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { AppModule } from './app.module';
import * as path from 'path';

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  app.useStaticAssets(path.join(__dirname, '..', 'public'));
  await app.listen(3000);
}

bootstrap();

At least this is what I'm using, and it works perfectly. Let me know if you need any more help!

from serve-static.

kennylbj avatar kennylbj commented on April 24, 2024 1

I am wondering what's the difference between this module and useStaticAssets under the hood?
And is there any drawback if I use this module to serve static assets like images and videos instead of useStaticAssets method?

from serve-static.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.