Приложение работает в среде разработчиков.При развертывании в Heroku сервер запускается, но появляется сообщение об ошибке «Требуется заголовок авторизации», сгенерированное из строки 24 файла root / index.js
Запуск аутентификации через Okta.Я изменил принятые URI для входа / выхода из системы / перенаправления / cors на соответствующий сервер Heroku.
Герокулоги:
State changed from crashed to starting
2019-02-09T04:36:51.316972+00:00 heroku[web.1]: Starting process with command `npm start`
2019-02-09T04:36:54.907936+00:00 app[web.1]:
2019-02-09T04:36:54.907953+00:00 app[web.1]: > oktapresent@1.0.0 start /app
2019-02-09T04:36:54.907955+00:00 app[web.1]: > node index.js
2019-02-09T04:36:54.907956+00:00 app[web.1]:
2019-02-09T04:36:55.780287+00:00 app[web.1]: Sat, 09 Feb 2019 04:36:55 GMT sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators at node_modules/sequelize/lib/sequelize.js:242:13
2019-02-09T04:36:55.807251+00:00 app[web.1]: Server is running
2019-02-09T04:36:55.808059+00:00 app[web.1]: production
2019-02-09T04:36:55.980108+00:00 heroku[web.1]: Process exited with status 0
2019-02-09T04:36:56.171358+00:00 heroku[web.1]: State changed from starting to crashed
2019-02-09T04:36:56.950835+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=powerful-brushlands-39786.herokuapp.com request_id=ff2b2683-e1d0-4394-91e3-12567cfa1ee9 fwd="35.132.178.245" dyno= connect= service= status=503 bytes= protocol=https
2019-02-09T04:36:57.454800+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=powerful-brushlands-39786.herokuapp.com request_id=fea276a0-e950-4079-991c-54c408599159 fwd="35.132.178.245" dyno= connect= service= status=503 bytes= protocol=https
2019-02-09T04:37:03.658916+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=powerful-brushlands-39786.herokuapp.com request_id=81b21d35-28b6-4186-b436-1c47714da4cb fwd="35.132.178.245" dyno= connect= service= status=503 bytes= protocol=https
2019-02-09T04:37:04.109715+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=powerful-brushlands-39786.herokuapp.com request_id=d889da89-f60b-4ad4-a36d-d0c1268e36f7 fwd="35.132.178.245" dyno= connect= service= status=503 bytes= protocol=https
Мой код:
const express = require("express");
const path = require("path-parser");
const cors = require("cors");
const bodyParser = require("body-parser");
const Sequelize = require("sequelize");
const epilogue = require("epilogue");
const OktaJwtVerifier = require("@okta/jwt-verifier");
const app = express();
const oktaJwtVerifier = new OktaJwtVerifier({
clientId: "0oaacx81uD0ndjUyF356",
issuer: "https://bigfootwebservice.okta.com/oauth2/ausacu2zhRbgylKNP356"
});
app.use(cors());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(async (req, res, next) => {
try {
if (!req.headers.authorization)
throw new Error("Authorization header is required");
const accessToken = req.headers.authorization.trim().split(" ")[1];
await oktaJwtVerifier.verifyAccessToken(accessToken);
next();
} catch (error) {
next(error.message);
}
});
const database = new Sequelize({
dialect: "sqlite",
storage: "./test.sqlite"
});
const Post = database.define("posts", {
title: Sequelize.STRING,
body: Sequelize.TEXT
});
epilogue.initialize({ app, sequelize: database });
epilogue.resource({
model: Post,
endpoints: ["/posts", "/posts/:id"]
});
const PORT = process.env.SERVER_PORT || 3001;
app.listen = PORT;
console.log("Server is running");
console.log(process.env.NODE_ENV);