SORU
7 Mayıs 2011, CUMARTESİ


-Js Express't statik dosyalarımı alabilir, neden?

Yapabilirim app express-js basit kodumu azalttım:

var express = require("express"),
    app = express.createServer();
app.use(express.static(__dirname   '/styles'));
app.listen(3001);

Benim dizin şöyle:

static_file.js
/styles
  default.css

Ben henüz 7 ** eriştiğinizde, aşağıdaki hata iletisini alabilirsiniz:

Cannot GET / styles /
default.css

express 2.3.3 node 0.4.7 kullanıyorum. Neyi yanlış yapıyorum?

CEVAP
7 Mayıs 2011, CUMARTESİ


http://localhost:3001/default.css deneyin.

İsteğinizi /styles URL, kullanımı:

app.use("/styles", express.static(__dirname   '/styles'));

this page: Bu örnek bak

//Serve static content for the app from the "public" directory in the application directory.

    // GET /style.css etc
    app.use(express.static(__dirname   '/public'));

// Mount the middleware at "/static" to serve static content only when their request path is prefixed with "/static".

    // GET /static/style.css etc.
    app.use('/static', express.static(__dirname   '/public'));

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Break

    Break

    10 Aralık 2005
  • FullMag

    FullMag

    15 ŞUBAT 2007
  • GoogleTechTalks

    GoogleTechTa

    15 AĞUSTOS 2007