<commit_before>"use strict"

express = require "express"
bodyParser = require "body-parser"
cookieParser = require "cookie-parser"
passport = require "passport"
session = require "express-session"
morgan = require "morgan"

config = require "../config.json"
routes = require "./routes/index.js"

require "./common/passportConfig.js"

app = express()
port = process.env.PORT || config.port
opt =
	root: __dirname
# TODO Not keyboard cat... but what should it be? What are these options anyway?
sessionConf =
	secret: "keyboard cat"
	resave: false
	saveUninitialized: true

app.use morgan "dev"
# TODO Warning The default server-side session storage, MemoryStore, is
# purposely not designed for a production environment. It will leak memory
# under most conditions, does not scale past a single process, and is meant
# for debugging and developing.
app.use session sessionConf
app.use express.static __dirname
app.use bodyParser.json()
app.use cookieParser()
app.use passport.initialize()
app.use passport.session()

###TODO
Honestly not even sure if all of this stuff works. That's why I'm creating a
branch. When I finally get it all working, I'll have a good, clean auth feature,
and I'll just commit those changes in one commit to the master branch without
keeping this history full of bumbling. :)

Guess I'll probably commit when I have the auth working with stubbed db stuff.
The real db implementation will come later.
###

routes.forEach (rt) ->
	auth = passport.authenticate "bearer", { session: false }
	middleware = if !rt.auth then rt.fn else [ rt.fn, auth ]
	app[rt.verb] "/api#{rt.path}", middleware

app.all "*", (req, res) ->
	res.sendFile "index.html", opt

app.listen (port), ->
	console.log "All systems are go! Port: #{port}"<commit_msg>Middleware was backwards<commit_after>"use strict"

express = require "express"
bodyParser = require "body-parser"
cookieParser = require "cookie-parser"
passport = require "passport"
session = require "express-session"
morgan = require "morgan"

config = require "../config.json"
routes = require "./routes/index.js"

require "./common/passportConfig.js"

app = express()
port = process.env.PORT || config.port
opt =
	root: __dirname
# TODO Not keyboard cat... but what should it be? What are these options anyway?
sessionConf =
	secret: "keyboard cat"
	resave: false
	saveUninitialized: true

app.use morgan "dev"
# TODO Warning The default server-side session storage, MemoryStore, is
# purposely not designed for a production environment. It will leak memory
# under most conditions, does not scale past a single process, and is meant
# for debugging and developing.
app.use session sessionConf
app.use express.static __dirname
app.use bodyParser.json()
app.use cookieParser()
app.use passport.initialize()
app.use passport.session()

###TODO
Honestly not even sure if all of this stuff works. That's why I'm creating a
branch. When I finally get it all working, I'll have a good, clean auth feature,
and I'll just commit those changes in one commit to the master branch without
keeping this history full of bumbling. :)

Guess I'll probably commit when I have the auth working with stubbed db stuff.
The real db implementation will come later.
###

routes.forEach (rt) ->
	auth = passport.authenticate "bearer", { session: false }
	middleware = if !rt.auth then rt.fn else [ auth, rt.fn ]
	app[rt.verb] "/api#{rt.path}", middleware

app.all "*", (req, res) ->
	res.sendFile "index.html", opt

app.listen (port), ->
	console.log "All systems are go! Port: #{port}"
{'fraction_non_alphanumeric': 0.10382978723404256, 'fraction_numerical': 0.0, 'mean_word_length': 4.466666666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '85867', 'n_tokens_mistral': 1033, 'n_tokens_neox': 1017, 'n_words': 435}