私はserver.useで立ち往生していますが、node.jsです。私がserver.use(express.static('public'));
をserver.get
の前に取るたびに、それは実行されません。そして、server.get()
の後に、私はserver.use(express.static('public'));
を変更します。server.use()につきました
誰かが私に何か違いを教えてもらえますか?
ここに私のスクリプト:
// Depedencies/built-in
import express from 'express';
import { join } from 'path';
import nodeSass from 'node-sass-middleware';
// you can place anything here, except depedencies
import config from './config';
import apiRouter from './api/index';
const server = express();
// Including Middleware
server.use(nodeSass({
src: join(__dirname + 'sass'),
dest: join(__dirname + 'public'),
}));
// everytime i take this before Router, it running, but
// but, the index won't showing up
server.use(express.static('public'));
// Setting up view engine
server.set('view engine', 'ejs');
// Router
server.get('/', (req, res) => {
res.render('index', {
title: 'Hello EJs',
});
});
// if i change after Route, it working well
// server.use(express.static('public'));
server.listen(config.port,() => {
console.log('magic happen on port: ', config.port);
});
答えてくれてありがとう、私はこれを私のメモに書きます。 – AinulBedjo
viewsディレクトリ内にindex.ejsを作成する必要がありますが、何も変更されていません Umm ..私は 'server.use(express.static( 'public'))'を '起こりました。私はちょうど 'server.use(express.static( 'public'))'を取る方法を知りませんし、もし上または下を取ると違いは – AinulBedjo
あなたは 'server.use(express.static(__ dirname + '/ public')) '? –