Création initiale du projet Amber

This commit is contained in:
2018-09-03 23:08:32 +02:00
parent a2c4523880
commit 6d4cadc2ae
35 changed files with 781 additions and 2 deletions

131
config/application.cr Normal file
View File

@ -0,0 +1,131 @@
require "./initializers/**"
require "amber"
require "../src/controllers/application_controller"
require "../src/controllers/**"
# About Application.cr File
#
# This is Amber application main entry point. This file is responsible for loading
# initializers, classes, and all application related code in order to have
# Amber::Server boot up.
#
# > We recommend to not modify the order of the require since the order will
# affect the behavior of the application.
#
# With `Amber::Server.configure` block you can redefine the Server configuration
# settings and use ENVIRONMENT variables and/or values evaluated at runtime.
#
# > Important! Yaml configurations are first class citizen and are loaded first before
# this file, we recommend to use yaml configurations before changing any settings here.
# Any uncommented setting here will override the YAML with the value set here.
Amber::Server.configure do |settings|
# Use your environment variables settings here.
#
# Name: A name that identifies this application. This is not internally
# used by the framework.
#
# settings.name = "Cdj Carnetdejeu web application."
#
#
# Colorize Logging: specifies whether or not to use ANSI color codes
# when logging information, display the time and/or to display the severity level.
# Defaults to true.
#
# Log Level defines the verbosity of the Amber logger. This option defaults to
# debug for all environments. The available log levels are: debug, info, warn,
# error, fatal, and unknown.
#
# settings.logging.colorize = true
# settings.logging.severity = "debug"
# settings.logging.filter = %w(password confirm_password)
# settings.logging.skip = %w()
# settings.logging.context = %w(request headers cookies session params)
#
#
# Secret Key Base: is used for specifying a key which allows sessions
# for the application to be verified against a known secure key to
# prevent tampering. Applications get Amber.secret_key
# initialized to a random key present in `ENV["AMBER_SECRET_KEY"]` or
# `.amber_secret_key` in this order.
#
# settings.secret_key_base= FEHWm3Fpm7vrPejFPM9x-3PLkj7C_fho6N-nIaBa19g
#
#
# Host: is the application server host address or ip address. Useful for when
# deploying Amber to a PAAS and likely the assigned server IP is either
# known or unknown. Defaults to an environment variable HOST
#
# settings.host = ENV["HOST"] if ENV["HOST"]?
#
#
# Port Reuse: Amber supports clustering mode which allows to spin
# multiple app instances per core. This setting allows to bind the different
# instances to the same port. Default this setting to true if the number or process
# is greater than 1.
#
# > Read more about Linux PORT REUSE https://lwn.net/Articles/542629/
#
# settings.port_reuse = true
#
#
# Process Count: This will enable Amber to be used in cluster mode,
# spinning an instance for each number of process specified here.
# Rule of thumb, always leave at least 1 core available for system processes/resources.
#
# settings.process_count = ENV["PROCESS_COUNT"].to_i if ENV["PROCESS_COUNT"]?
#
#
# PORT: This is the port that you're application will run on. Examples would be (80, 443, 3000, 8080)
#
settings.port = ENV["PORT"].to_i if ENV["PORT"]?
#
#
# Redis URL: Redis is an in memory key value storage. Amber utilizes redis as
# a storing option for session information.
#
# settings.redis_url = ENV["REDIS_URL"] if ENV["REDIS_URL"]?
#
#
# Database URL: This is the database connection string or data file url.
# The connection string contains the information to establish a connection to the
# database or the data file. Defaults to the database provider you chose at
# at app generation.
#
# settings.database_url = ENV["DATABASE_URL"] if ENV["DATABASE_URL"]?
#
#
# SSL Key File: The private key is a text file used initially to generate a
# Certificate Signing Request (CSR), and later to secure and verify connections
# using the certificate created per that request. The private key is used to create
# a digital signature as you might imagine from the name, the private key should be
# ``closely guarded.
#
# settings.ssl_key_file = ENV["SSL_KEY_FILE"] if ENV["SSL_KEY_FILE"]?
#
#
# SSL Cert File: This represents the signed certificate file. SSL Certificates are
# small data files that digitally bind a cryptographic key to an organization's
# details. When installed on a web server, it activates the padlock and the https
# protocol and allows secure connections from a web server to a browser.
#
# settings.ssl_cert_file = ENV["SSL_CERT_FILE"] if ENV["SSL_CERT_FILE"]?
#
#
# Session: A Hash that specifies the session storage mechanism, expiration and key to be used
# for the application. The `key` specifies the name of the cookie to be used defaults to
# "amber.session". The store can be `encrypted_cookie`, `signed_cookie` or `redis`. Expires
# when set to 0 means this is indefinitely and is expressed in seconds.
#
# settings.session = { "key" => "amber.session", "store" => "signed_cookie", "expires" => 0 }
#
#
# Logger: is the logger that Amber and other capable shards in the project will use
# instead of writing directly to STDOUT. Supply a custom logger to write to syslog, etc.
#
# settings.logger = Amber::Environment::Logger.new(File.open("cdj_carnetdejeu.log", "w"))
#
#
end

Binary file not shown.

View File

@ -0,0 +1,36 @@
secret_key_base: cie0hbJtXS-F51akAYdEeNof67tLG4q-L5bpaLqgPTE
port: 3000
name: cdj_carnetdejeu
logging:
severity: debug
colorize: true
filter:
- password
- confirm_password
context:
- request
- session
- headers
- cookies
- params
host: 0.0.0.0
port_reuse: true
process_count: 1
# ssl_key_file:
# ssl_cert_file:
redis_url: "redis://localhost:6379"
database_url: postgres://postgres:@localhost:5432/cdj_carnetdejeu_development
session:
key: amber.session
store: signed_cookie
expires: 0
smtp:
enabled: false
secrets:
description: Store your development secrets credentials and settings here.

View File

@ -0,0 +1,36 @@
secret_key_base: 2jEkAoKdioIl6U1W0T-Zu2U7V5HRQ3-GpeIxOeEVjms
port: 3000
name: cdj_carnetdejeu
logging:
severity: debug
colorize: true
filter:
- password
- confirm_password
context:
- request
- session
- headers
- cookies
- params
host: 0.0.0.0
port_reuse: false
process_count: 1
# ssl_key_file:
# ssl_cert_file:
redis_url: "redis://localhost:6379"
database_url: postgres://postgres:@localhost:5432/cdj_carnetdejeu_test
session:
key: amber.session
store: signed_cookie
expires: 0
smtp:
enabled: false
secrets:
description: Store your development secrets credentials and settings here.

View File

@ -0,0 +1,6 @@
require "granite/adapter/pg"
Granite::Adapters << Granite::Adapter::Pg.new({name: "pg", url: Amber.settings.database_url})
Granite.settings.logger = Amber.settings.logger.dup
Granite.settings.logger.progname = "Granite"

View File

@ -0,0 +1,24 @@
require "citrine-i18n"
Citrine::I18n.configure do |settings|
# Backend storage (as supported by i18n.cr)
# settings.backend = I18n::Backend::Yaml.new
# Default locale (defaults to "en" and "./src/locales/**/en.yml").
# For a new default locale to be accepted, it must be found by the
# backend storage and reported in "settings.available_locales".
# settings.default_locale = "en"
# Separator between sublevels of data (defaults to '.')
# e.g. I18n.translate("some/thing") instead of "some.thing"
# settings.default_separator = '.'
# Returns the current exception handler. Defaults to an instance of
# I18n::ExceptionHandler.
# settings.exception_handler = ExceptionHandler.new
# The path from where the translations should be loaded
settings.load_path += ["./src/locales"]
end
I18n.init

42
config/routes.cr Normal file
View File

@ -0,0 +1,42 @@
Amber::Server.configure do
pipeline :web do
# Plug is the method to use connect a pipe (middleware)
# A plug accepts an instance of HTTP::Handler
plug Amber::Pipe::PoweredByAmber.new
# plug Amber::Pipe::ClientIp.new(["X-Forwarded-For"])
plug Citrine::I18n::Handler.new
plug Amber::Pipe::Error.new
plug Amber::Pipe::Logger.new
plug Amber::Pipe::Session.new
plug Amber::Pipe::Flash.new
plug Amber::Pipe::CSRF.new
end
pipeline :api do
plug Amber::Pipe::PoweredByAmber.new
plug Amber::Pipe::Error.new
plug Amber::Pipe::Logger.new
plug Amber::Pipe::Session.new
plug Amber::Pipe::CORS.new
end
# All static content will run these transformations
pipeline :static do
plug Amber::Pipe::PoweredByAmber.new
plug Amber::Pipe::Error.new
plug Amber::Pipe::Static.new("./public")
end
routes :web do
get "/", HomeController, :index
end
routes :api do
end
routes :static do
# Each route is defined as follow
# verb resource : String, controller : Symbol, action : Symbol
get "/*", Amber::Controller::Static, :index
end
end

69
config/webpack/common.js Normal file
View File

@ -0,0 +1,69 @@
const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
let config = {
entry: {
'main.bundle.js': './src/assets/javascripts/main.js',
'main.bundle.css': './src/assets/stylesheets/main.scss'
},
output: {
filename: '[name]',
path: path.resolve(__dirname, '../../public/dist'),
publicPath: '/dist'
},
resolve: {
alias: {
amber: path.resolve(__dirname, '../../lib/amber/assets/js/amber.js')
}
},
module: {
rules: [
{
test: /\.css$/,
exclude: /node_modules/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader'
})
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
},
{
test: /\.(png|svg|jpg|gif)$/,
exclude: /node_modules/,
use: [
'file-loader?name=/images/[name].[ext]'
]
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
exclude: /node_modules/,
use: [
'file-loader?name=/[name].[ext]'
]
},
{
test: /\.js?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['env']
}
}
]
},
plugins: [
new ExtractTextPlugin('main.bundle.css'),
],
// For more info about webpack logs see: https://webpack.js.org/configuration/stats/
stats: 'errors-only'
};
module.exports = config;

View File

@ -0,0 +1,7 @@
const webpack = require('webpack');
const merge = require('webpack-merge');
const common = require('./common.js');
module.exports = merge(common, {
devtool: 'inline-source-map'
});

View File

@ -0,0 +1,11 @@
const webpack = require('webpack');
const merge = require('webpack-merge');
const common = require('./common.js');
module.exports = merge(common, {
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: { warnings: false }
})
]
});