【发布时间】:2020-12-23 23:43:24
【问题描述】:
所以,这很奇怪。我正在使用 Express 和 Pug 运行 Nodejs 应用程序。我的所有静态文件都在 Public 文件夹中,我的 Pug 文件在 Views 文件夹中。我设置了 app.js 文件以从 Public 文件夹中获取所有静态文件。我正在使用 Nginx 来处理服务器。
这是奇怪的部分,当我使用 AWS 在 Ubuntu 实例上运行它时,我的所有 js 和 css 文件都得到 404。当我在本地计算机上运行它时,我收到 304 错误,但一切正常。
任何想法我做错了什么?我将在下面展示我的一些代码。
哈巴狗文件
doctype html
html
head
meta(charset='utf-8')
title Signature Pad
meta(name='description', content='Signature Pad - HTML5 canvas based smooth signature drawing using variable width spline interpolation.')
meta(name='viewport', content='width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no')
meta(name='apple-mobile-web-app-capable', content='yes')
meta(name='apple-mobile-web-app-status-bar-style', content='black')
link(rel='stylesheet', href='stylesheets/signature-pad.css')
#signature-pad.signature-pad
.signature-pad--body
canvas
.signature-pad--footer
div
.description Sign Above
.signature-pad--actions
div
button.button.clear(type='button', data-action='clear') Clear
button.button(type='button', data-action='undo') Undo
div
form(action='', method='POST', onsubmit='completeAndRedirect();return false;')
label(for='fname') First name:
input#firstName(type='text', name='fname')
label(for='lname') Last name:
input#lastName(type='text', name='lname')
br
br
label(for='company') Company:
input#company(type='text', name='company')
br
br
input.button.save(type='submit', value='Submit', data-action='save-svg')
script(src='js/signature_pad.umd.js')
script(src='js/app.js')
App.js 文件
const express = require('express');
const path = require('path');
const NetSuiteOauth = require('netsuite-tba-oauth');
const bodyParser = require('body-parser');
const app = express();
//Parse incoming request
app.use(bodyParser.json());
//app.use(bodyParser.urlencoded({ extended: false }));
//View engine
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
//Static Files
app.use(express.static(__dirname + '/Public'));
app.get('/', (req, res, next)=> {
return res.render('landing', {title: 'Home'})
});
app.get('/customer', (req, res, next)=> {
return res.render('signature', {title: 'Customer'})
});
app.get('/employee', (req, res, next)=> {
return res.render('signature', {title: 'Employee'})
});
app.post('/customer', (req, res, next)=>{
return res.render('entered', {title: 'Home'})
});
app.post('/employee', (req, res, next)=>{
return res.render('entered', {title: 'Home'})
});
app.listen(8080);
文件夹结构
如果我不清楚,请告诉我,第一次在 Stack 上摆姿势
【问题讨论】:
标签: node.js nginx http-status-code-404 pug http-status-code-304