This repository has been archived by the owner on Mar 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f165d93
commit 37d73ea
Showing
3 changed files
with
1,244 additions
and
1,002 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,3 @@ If this does not make sense to you, then consult the JavaScript documentation ht | |
The simplest case is getZones as it is a GET request, whereas the rest are POSTs, so this can be accessed in the browser. | ||
Going to `localhost:3000/stockTake/getZones` you will see the output. | ||
|
||
## MongoDB URL | ||
`mongodb+srv://new-user:[email protected]/test?retryWrites=true&w=majority` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,60 @@ | ||
var bodyParser = require('body-parser'); | ||
var createError = require('http-errors'); | ||
var express = require('express'); | ||
var path = require('path'); | ||
var cookieParser = require('cookie-parser'); | ||
var logger = require('morgan'); | ||
var cors = require("cors") | ||
var bodyParser = require("body-parser"); | ||
var createError = require("http-errors"); | ||
var express = require("express"); | ||
var path = require("path"); | ||
var cookieParser = require("cookie-parser"); | ||
var logger = require("morgan"); | ||
var cors = require("cors"); | ||
|
||
|
||
|
||
let stockTakeRouter = require('./routes/stockTake') | ||
let stockTakeRouter = require("./routes/stockTake"); | ||
|
||
var app = express(); | ||
app.use(cors()) | ||
|
||
|
||
app.use(cors()); | ||
|
||
// view engine setup | ||
app.set('views', path.join(__dirname, 'views')); | ||
app.set('view engine', 'pug'); | ||
app.set("views", path.join(__dirname, "views")); | ||
app.set("view engine", "pug"); | ||
//app.set('view engine', 'jade'); | ||
|
||
app.use(logger('dev')); | ||
app.use(logger("dev")); | ||
app.use(express.json()); | ||
app.use(express.urlencoded({ extended: false })); | ||
app.use(cookieParser()); | ||
app.use(express.static(path.join(__dirname, 'public'))); | ||
app.use(express.static(path.join(__dirname, "public"))); | ||
app.use(bodyParser.json()); | ||
|
||
app.use(function(req, res, next) { | ||
app.use(function (req, res, next) { | ||
if (!req.headers.authorization) { | ||
return res.status(403).json({ error: 'No credentials sent!' }); | ||
return res.status(403).json({ error: "No credentials sent!" }); | ||
} | ||
if (req.headers.authorization!=="YWxhZGRpbjpvcGVuc2VzYW1l") { | ||
return res.status(403).json({ error: 'Invalid credentials' }); | ||
if ( | ||
req.headers.authorization !== | ||
Math.random() | ||
.toString(36) | ||
.replace(/[^a-z]+/g, "") | ||
.substr(0, 5) | ||
) { | ||
return res.status(403).json({ error: "Invalid credentials" }); | ||
} | ||
next(); | ||
}); | ||
|
||
|
||
app.use('/stockTake', stockTakeRouter); | ||
app.use("/stockTake", stockTakeRouter); | ||
|
||
// catch 404 and forward to error handler | ||
app.use(function(req, res, next) { | ||
app.use(function (req, res, next) { | ||
next(createError(404)); | ||
}); | ||
|
||
// error handler | ||
app.use(function(err, req, res, next) { | ||
app.use(function (err, req, res, next) { | ||
// set locals, only providing error in development | ||
res.locals.message = err.message; | ||
res.locals.error = req.app.get('env') === 'development' ? err : {}; | ||
res.locals.error = req.app.get("env") === "development" ? err : {}; | ||
|
||
// render the error page | ||
res.status(err.status || 500); | ||
res.render('error'); | ||
res.render("error"); | ||
}); | ||
|
||
module.exports = app; |
Oops, something went wrong.